기본 콘텐츠로 건너뛰기

라벨이 functions인 게시물 표시

firebase functions 위에 올라간 apollo server 에 apollo engine 끼얹기

이전 글에서 계속. https://www.apollographql.com/docs/engine/setup-node.html  보고 진행해보자. 미리 가입하고 키도 받아놓자. ENGINE_API_KEY 를 잘 copy 해놓자. app.use '/graphql',   bodyParser.json()   graphqlExpress {     schema     context: {}     tracing: true     cacheControl: true   } 먼저 /graphql 쪽 graphqlExpress 에 두개의 키(tracing, cacheControl)를 추가하자. npm install --save compression apollo-engine 두 패키지를 설치하고 compression = require 'compression' { Engine } = require 'apollo-engine' 압축과 엔진을 추가하고 engine을 하나 만들자. engine = new Engine   engineConfig:     apiKey: 'service:acidsound-6459:wKt62uPKS9dmxmBhFh-cZA'   endpoint: '/api/graphql'   graphqlPort: process.env.PORT or 80 engine.start() 여기서 graphqlPort를 지정하지 않으면  Error: Neither 'graphqlPort' nor process.env.PORT is set. In order for Apollo Engine to act as a proxy for your GraphQL server, it needs to know which port your GraphQL server...

firebase /w functions + graphQL backend 만들기

persistence 영역을 graphQL 로 일반화 하고 apollo engine 같은 cache를 사용하고 싶다. firebase의 functions를 통해 firebase를 불러오는 건 사실상 이중 작업인 것 같지만 apollo engine이 매우 맘에 들어 끌어들이고 싶다. 먼저 해볼 것은 functions에 graphql을 집어넣고 정적데이터를 읽어오는 것 먼저 로컬에서 구현해본다. 프로젝트 폴더를 생성하고 firebase init functions 부터 하자. 프로젝트를 선택(혹은 생성하고 ? What language would you like to use to write Cloud Functions? JavaScript ✔  Wrote functions/package.json ✔  Wrote functions/index.js 그냥 firebase init 하고 functions를 선택하는 것과는 달리 뭔가 기본 scaffold를 생성해줘서 좋다. {   "functions": {     "source": "functions"   } } 디폴트로 이렇게 해주자. index.coffee 로 get 테스트. exports하는 놈 이름이 functions 이름이 되고 경로도 /[exports한 놈]/ 이 되는 점이 특징이다. functions = require 'firebase-functions' admin = require 'firebase-admin' admin.initializeApp functions.config().firebase exports.addMessage = functions.https.onRequest (req, res)->   original = req.query.text?   admin.firestore()     .collection 'messages'     .add { origin...

Firebase Functions - backend 로직을 구축해보자.

아예 functions라는 이름의 HTTP기반 node.js application 도 올릴 수 있다. 잘하면 meteor도 올릴 수 있을 거 같긴한데 일단 나중에 볼 일이고 https://firebase.google.com/docs/functions/get-started  따라 해보자 먼저 init 부터 $ firebase init functions      🔥🔥🔥🔥🔥🔥🔥🔥 🔥🔥🔥🔥 🔥🔥🔥🔥🔥🔥🔥🔥  🔥🔥🔥🔥🔥🔥🔥🔥 🔥🔥🔥🔥🔥🔥🔥🔥     🔥🔥🔥     🔥🔥🔥🔥🔥🔥  🔥🔥🔥🔥🔥🔥🔥🔥      🔥🔥        🔥🔥  🔥🔥     🔥🔥 🔥🔥       🔥🔥     🔥🔥  🔥🔥   🔥🔥  🔥🔥       🔥🔥      🔥🔥🔥🔥🔥🔥    🔥🔥  🔥🔥🔥🔥🔥🔥🔥🔥  🔥🔥🔥🔥🔥🔥   🔥🔥🔥🔥🔥🔥🔥🔥  🔥🔥🔥🔥🔥🔥🔥🔥🔥  🔥🔥🔥🔥🔥🔥  🔥🔥🔥🔥🔥🔥      🔥🔥        🔥🔥  🔥🔥    🔥🔥  🔥🔥       🔥🔥     🔥🔥 🔥🔥     🔥🔥       🔥🔥 🔥🔥      🔥🔥     ...