> firebase --version
3.17.1
> node --version
v6.12.3
> npm --version
5.6.0
> git clone https://github.com/firebase/functions-samples.git
> cd functions-samples/authenticated-json-api/functions/
> npm install
> [email protected] install /Users/karl/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library
[grpc] Success: "/Users/karl/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/grpc/src/node/extension_binary/node-v48-darwin-x64-unknown/grpc_node.node" is installed via remote
> [email protected] postinstall /Users/karl/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/protobufjs
> node scripts/postinstall
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] requires a peer of firebase-admin@~4.2.1 but none is installed. You must install peer dependencies yourself.
added 354 packages in 11.832s
> firebase use my-project
Now using project my-project
> firebase serve --only functions
=== Serving from '/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api'...
i functions: Preparing to emulate functions.
โ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
โ functions: Error from emulator. FirebaseError: Error occurred while parsing your function triggers. Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder.
Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function.
at init (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:51:15)
at Object.config (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:29:9)
at Object.<anonymous> (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/index.js:27:31)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
> firebase serve --only functions --debug
[2018-01-19T03:30:49.455Z] ----------------------------------------------------------------------
[2018-01-19T03:30:49.459Z] Command: /usr/local/Cellar/node@6/6.12.3/bin/node /usr/local/bin/firebase serve --only functions --debug
[2018-01-19T03:30:49.460Z] CLI Version: 3.17.1
[2018-01-19T03:30:49.460Z] Platform: darwin
[2018-01-19T03:30:49.460Z] Node Version: v6.12.3
[2018-01-19T03:30:49.460Z] Time: Thu Jan 18 2018 22:30:49 GMT-0500 (EST)
[2018-01-19T03:30:49.461Z] ----------------------------------------------------------------------
[2018-01-19T03:30:49.476Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2018-01-19T03:30:49.476Z] > authorizing via signed-in user
[2018-01-19T03:30:49.479Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/my-project
Thu Jan 18 2018 22:30:49 GMT-0500 (EST)
[2018-01-19T03:30:49.855Z] <<< HTTP RESPONSE 200 server=nginx, date=Fri, 19 Jan 2018 03:30:49 GMT, content-type=application/json; charset=utf-8, content-length=126, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store
[2018-01-19T03:30:49.856Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/my-project/tokens
Thu Jan 18 2018 22:30:49 GMT-0500 (EST)
[2018-01-19T03:30:50.482Z] <<< HTTP RESPONSE 200 server=nginx, date=Fri, 19 Jan 2018 03:30:50 GMT, content-type=application/json; charset=utf-8, content-length=267, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store
=== Serving from '/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api'...
i functions: Preparing to emulate functions.
[2018-01-19T03:30:51.081Z] Fetching environment
[2018-01-19T03:30:51.082Z] >>> HTTP REQUEST GET https://appengine.googleapis.com/v1/apps/my-project
Thu Jan 18 2018 22:30:51 GMT-0500 (EST)
[2018-01-19T03:30:51.083Z] >>> HTTP REQUEST GET https://apikeys.googleapis.com/v1/projects/my-project/apiKeys
Thu Jan 18 2018 22:30:51 GMT-0500 (EST)
[2018-01-19T03:30:51.569Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Fri, 19 Jan 2018 03:30:51 GMT, server=ESF, cache-control=private, x-xss-protection=1; mode=block, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35", accept-ranges=none, connection=close
[2018-01-19T03:30:51.663Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Fri, 19 Jan 2018 03:30:51 GMT, server=ESF, cache-control=private, x-xss-protection=1; mode=block, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35", accept-ranges=none, connection=close
[2018-01-19T03:30:51.664Z] Starting @google-cloud/functions-emulator
[2018-01-19T03:30:53.220Z] Parsing function triggers
โ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
โ functions: Error from emulator. FirebaseError: Error occurred while parsing your function triggers. Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder.
Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function.
at init (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:51:15)
at Object.config (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:29:9)
at Object.<anonymous> (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/index.js:27:31)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
๋ค๋ฅธ ํ๋ก์ ํธ์์ firebase serve --only functions
๊ฐ ์ ์ง๋๊ณ ๋ค๋ฅธ ์ํ์ ๋ง์ด ์๋ํ๊ธฐ ๋๋ฌธ์ ๋งค์ฐ ์ด์ํฉ๋๋ค. ์ด๋ ๊ฒ์์๋ ์๋ํ์ง ์์ต๋๋ค.
์ด๋ฏธ ๋ฐฐํฌํ ๊ธฐ๋ฅ์์๋ ์๋ํ์ง ์์ต๋๋ค.
firebase serve --only functions
๋์ functions ๋๋ ํ ๋ฆฌ ๋ด๋ถ์์ npm run serve
๋ฅผ ์คํํด ๋ณด์ญ์์ค. ์ด๊ฒ์ package.json ํ์ผ์ด ๊ตฌ์ฑ๋ ๋ฐฉ์์ ๋ฐ๋ผ ์๋ํ ์๋ ์๊ณ ์๋ํ์ง ์์ ์๋ ์์ต๋๋ค.
๋ถํํ๋ ์ด์ ๋ํด ๊ตฌ์ฑ๋ package.json์ด ์์ต๋๋ค.
> npm run serve
npm ERR! Darwin 17.3.0
npm ERR! argv "/Users/alchemist/.nvm/versions/node/v6.11.5/bin/node" "/Users/karl/.nvm/versions/node/v6.11.5/bin/npm" "run" "serve"
npm ERR! node v6.11.5
npm ERR! npm v3.10.10
npm ERR! missing script: serve
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/npm-debug.log
ํ๋๋ง ์๋ ค์ค ์ ์๋?
์ด๊ฒ์ ์ ์ ํ firebase init
ํ์ ๋ด ๋ชจ์ต์
๋๋ค : https://gist.github.com/dylanjmcdonald/6c033b476e863efaea3eccc0b3137772
3.17.1๋ก ์
๋ฐ์ดํธํ ํ ์ค๋ฅ๊ฐ ์์๋ ์ดํ๋ก firebase-tools
๋ฅผ 3.16.0์ผ๋ก ๋ค์ด๊ทธ๋ ์ด๋ํ์ฌ ์ด ์ค๋ฅ๋ฅผ ํด๊ฒฐํ ์ ์์์ต๋๋ค.
๋๋ ๋ฐฐํฌ๋ฅผ ์ํด ์ต์ ๋ฒ์ ์ firebase-tools
๋ฅผ ์ค์นํ๊ณ ์์๋๋ฐ ๋ด CI ๋ฌ๋์์ ์ด ์ค๋ฅ๋ฅผ ์ฒ์ ๋ฐ๊ฒฌํ์ต๋๋ค. ๋ฐค์ ๋ด ๋ฐฐํฌ๊ฐ ์๋์ ๋ฉ์ท์ต๋๋ค. firebase-admin
๋ฐ firebase-functions
๋ฅผ ์
๊ทธ๋ ์ด๋ํ ํ ๋ค์ ์๋ํ๊ธฐ ์์ํ์ต๋๋ค.
๊ทธ๋ฌ๋ ๋ด ๋ก์ปฌ ํ๊ฒฝ์ด ์๋์ ๋ฉ์ท์ต๋๋ค. ์ฌ์ ํ ๋ฐฐํฌํ ์ ์์์ง๋ง ๊ธฐ๋ฅ์ ์ ๊ณตํ ์๋ ์์์ต๋๋ค. firebase-tools
๋ฅผ ์ ๊ฑฐํ๊ณ ๋ค์ ์ค์นํ๋ ค๊ณ ์๋ํ์ต๋๋ค... ๊ทธ๋ฆฌ๊ณ ๋ด๊ฐ ์๊ฐํด๋ผ ์ ์๋ ๋ชจ๋ ๋ณํ(์บ์ ์ ๋ฆฌ, ์ต์ NPM ์ฌ์ฉ, 6.11.5 ์ฌ์ฉ, Yarn ์ฌ์ฉ ๋ฑ). ๋ถ์ด.
๋ง์ง๋ง์ผ๋ก ๋ชจ๋ ๊ฒ์ ์ด์ ์ ์๋ํ๋ ๋ฒ์ ์ผ๋ก ๋กค๋ฐฑํ๊ณ CI ์คํฌ๋ฆฝํธ์ ์ฌ์ฉ๋ ๋ฒ์ ์ ๊ณ ์ ํ๊ธฐ๋ก ๊ฒฐ์ ํ์ต๋๋ค(์ต์ ๋์ ). ์ด์ ๋ ํ๊ฒฝ ๋ชจ๋ ์ผ๊ด๋๊ฒ ์๋ํฉ๋๋ค.
๋๋ ๋ช ๋ฌ ์ ์ ๋ค๋ฅธ ๊ฐ๋ฅํ ์๋ฃจ์ ์ผ๋ก ์ด ๋ฌธ์ ์ ๋ค์ํ ๋ณํ์ ๋ณด์์ต๋๋ค. ํด๋ณด๊ฐ ์๋๊น? ๋ถ๋ถ๋ช ํ ๊ทผ๋ณธ์ ์ธ ๋ฌธ์ ?
BTW: ์ ๋ macOS High Sierra 10.13.2๋ฅผ ๋ก์ปฌ๋ก ์คํํ๊ณ ์์ผ๋ฉฐ ๋์์ด ๋๋ ๊ฒฝ์ฐ GitLab์์ CI ์คํ๊ธฐ๋ฅผ ์ํ node:latest Docker ์ด๋ฏธ์ง๋ฅผ ์คํํ๊ณ ์์ต๋๋ค.
์ถ์ : ์ ๊ฒฝํ์ npm run dev
๋ ๋ด๋ถ์ ์ผ๋ก firebase serve --only functions
$๋ฅผ ์คํํฉ๋๋ค.
@rafasoares : ๊ฐ์ฌํฉ๋๋ค. 3.16.0์ผ๋ก ๋ค์ด๊ทธ๋ ์ด๋ํ๋ฉด ์ค๋ฅ๊ฐ ์์ ๋์์์ ํ์ธํ ์ ์์ต๋๋ค!
npm install -g [email protected]
macOS High Sierra 10.13.2๋ ์ฌ์ฉํ๊ณ ์์ง๋ง nvm
๋ฅผ ํตํด ์ค์น๋ ๋
ธ๋ v6.11.5๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
@-์ฐ๊ธ์ ์ฌ๋, ์ ๊ฐ ๋์๋๋ฆด ์ ์์ด์ ๊ธฐ์ฉ๋๋ค.
brew(9.x)๋ฅผ ํตํด ์ค์น๋ ์ต์ ๋ ธ๋์ nvm์ ํตํด ์ค์น๋ 6.11.5๋ฅผ ๋ชจ๋ ์ฌ์ฉํด ๋ณด์์ต๋๋ค. ์ด์ ์๋ ์ต์ ๋ ธ๋์์ ์๋ํ์ต๋๋ค(GCP ๋ ธ๋ ๋ฒ์ ๊ฒฝ๊ณ ์ ํจ๊ป).
์๋ ํ์ธ์ ์ฌ๋ฌ๋ถ, ์ต์ firebase-tools(3.17.1)์๋ ์ต์ firebase-functions SDK๊ฐ ํ์ํ๋ฏ๋ก ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ ์ข์ ๋ฐฉ๋ฒ์ functions ํด๋ ๋ด์์ "npm i --save firebase -functions@latest "๋ฅผ ์คํํ๋ ๊ฒ์ ๋๋ค. ์ค๋ฅ ๋ฉ์์ง์์ ์ ์ ์๋ฏ์ด ๋ฐฐํฌ ๋๋ ์ ๊ณตํ๊ธฐ ์ ์
@laurenzlong ์์ ๋ด ์๊ฒฌ์ ์ฝ์์ต๋๊น? ๊ฐ์ฅ ๋จผ์ ์๋ํ ๊ฒ์
๋๋ค. ๊ทธ ํ, ๋๋ firebase deploy --only functions
ํ ์ ์์์ง๋ง firebase serve --only functions
ํ ์ ์์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ๋ด๊ฐ ์๊ฐํด๋ผ ์ ์๋ ๋ชจ๋ ์ข ๋ฅ์ ์ ๋ฆฌ ์ ๋ต์ ์๋ํ์ต๋๋ค. ์์ ๋ณต์ฌ๋ณธ์ ์ญ์ ํ๊ณ Git์์ ๋ชจ๋ ๊ฒ์ ์ฒ์๋ถํฐ ๊ฐ์ ธ์์ต๋๋ค.
@rafasoares ์ฃ์กํฉ๋๋ค. ๊ทธ ๋ถ๋ถ์ ๋์ณค์ต๋๋ค. ์ง๊ธ๋ถํฐ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
์์ฒญ๋! ๊ฐ์ฌ ํด์!
v3.17.2๊ฐ ์ด์ ๋ฆด๋ฆฌ์ค๋์์ผ๋ฉฐ ๋ฌธ์ ๋ฅผ ์์ ํ์ด์ผ ํฉ๋๋ค. ํด๊ฒฐ๋์ง ์์ผ๋ฉด ์๋ ค์ฃผ์ญ์์ค. ์ ๊ณ ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!
๋ฐฉ๊ธ v3.17.2๋ฅผ ์๋ํ๋๋ฐ ์ ์๊ฒ ํจ๊ณผ์ ์ด์์ต๋๋ค!
๊ทธ๊ฒ์ ๋๋ฅผ ์ํด ์๋ํ์ง ์์๋ค. ๋๋ ๋น ํ๋ก์ ํธ์์ ์๋ํ๋๋ก ๊ด๋ฆฌํ์ง๋ง ํ์ฌ ํ๋ก์ ํธ๋ฅผ ์๋์ํค์ง ๋ชปํ์ต๋๋ค.
๊ทธ๋์ ์ฑ๊ตดํ๋ฌ ๊ฐ์ต๋๋ค. ๋์ ์ฐจ์ด์ ์ ๋ฌด์์ ๋๊น?
๋ฌธ์ ๋ฅผ ์ ํํ ์ง์ ํ ์ ์์์ต๋๋ค. ๋ค์ ์ฝ๋๋ฅผ ์ถ๊ฐํ๋ฉด ์ค๋จ๋ฉ๋๋ค.
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase); // <-- Specifically, this line
์ด๊ธฐํ ๋นํธ๋ฅผ ์ ๊ฑฐํ๋ฉด ๊ธฐ๋ฅ์ ์ํํ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ Firestore๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์
๋ฐ์ดํธ: functions.config().firebase
ํธ์ถ์ ๋ค์ JSON์ผ๋ก ๋ฐ๊พธ๋ฉด ์๋ํฉ๋๋ค.
{
databaseURL: 'https://[PROJECT_NAME].firebaseio.com',
storageBucket: '[PROJECT_NAME].appspot.com',
apiKey: '[API KEY]',
authDomain: '[PROJECT_NAME].firebaseapp.com',
projectId: '[PROJECT_NAME]',
credential: admin.credential.applicationDefault()
}
๊ทธ JSON์ [email protected]
$๋ฅผ ์ฌ์ฉํ ๋ functions.config().firebase
์ ์ถ๋ ฅ์ด์์ต๋๋ค(๋ฌธ์์์ ๊ฐ์ ธ์จ credential
๋นํธ ์ ์ธ).
ํ์ง๋ง ์ด ์ฝ๋๋ก ๋ฐฐํฌ๋ฅผ ์๋ํ์ง๋ ์์์ต๋๋ค.
@rafasoares google-cloud/functions-emulator ์ข ์์ฑ์ ๋ค์ด๊ทธ๋ ์ด๋ํ๋๋ฐ ์ฐจ์ด์ ์ ๋๋ค. "npm uninstall -g firebase-tools & npm i -g firebase-tools"๋ฅผ ์๋ํ์ญ์์ค. ๊ฐ์ง๊ณ ์๋ npm ๋ฒ์ ์ ๋ฐ๋ผ ๋จผ์ ์ ๊ฑฐ๋ฅผ ์ํํ์ง ์๋ ํ ์ข ์์ฑ์ ๋ค์ด๊ทธ๋ ์ด๋ํ์ง ์๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค.
@rafasoares semver ๋ฒ์ ๊ด๋ฆฌ๊ฐ ์๋ชป๋ ๊ฒ ๊ฐ์ต๋๋ค. #618์์ ์์ ํ ๊ฒ ๊ฐ์ต๋๋ค. ํด๋น ๋ถ๊ธฐ๋ฅผ ์ฌ์ฉํด ๋ณผ ์ ์์ต๋๊น?
npm ์ค์น -g https://github.com/firebase/firebase-tools.git#laurenzlong -patch-1
@laurenzlong
semver ๋ฒ์ ๊ด๋ฆฌ๊ฐ ์๋ชป๋ ๊ฒ ๊ฐ์ต๋๋ค. #618์์ ์์ ํ ๊ฒ ๊ฐ์ต๋๋ค. ํด๋น ๋ถ๊ธฐ๋ฅผ ์ฌ์ฉํด ๋ณผ ์ ์์ต๋๊น?
@rafasoares ์ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์๊ณ npm install -g https://github.com/firebase/firebase-tools.git#laurenzlong-patch-1
์๋ํ์ง๋ง ๋ฌธ์ ๊ฐ ๋จ์ ์์ต๋๋ค.
npm install -g [email protected]
ํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ฉ๋๋ค.
์ฃ์กํฉ๋๋ค. Yarn๊ณผ NPM์ด ์ฌ๋ฐ๋ฅธ ๋ฒ์ ์ ๋ค์ด๋ก๋ํ๋๋ก ํ๋ ค๊ณ ์ ์ฐ๊ณ ์์ต๋๋ค. ์ ํ๊ฒฝ์ ์๋ง์ผ๋ก ๋ง๋ ๊ฒ ๊ฐ์ต๋๋ค. ํํ.
๊ทธ๋ฌ๋ ์, https://github.com/firebase/firebase-tools.git#laurenzlong -patch-1์ @google-cloud/[email protected]
๊ฐ ์ค์น๋ ๋ฒ์ ์์๋ ๋ถ๊ตฌํ๊ณ ์ฌ์ ํ ์ค๋ฅ๋ฅผ ์ ๊ณตํฉ๋๋ค.
@mono0926 @rafasoares ์ด๊ฑด ์ด๋์?
npm ์ค์น -g https://github.com/firebase/firebase-tools.git#ll -fixemu
์ธ๋ด์ฌ๊ณผ ๋์์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค!
@laurenzlong
npm ์ค์น -g https://github.com/firebase/firebase-tools.git#ll -fixemu
๋ถํํ๋ ์ด๊ฒ์ ์ฌ์ ํ โโ๋์๊ฒ ์ค๋ฅ๋ฅผ ์ ๊ณตํฉ๋๋ค :(
npm uninstall -g firebase-tools && npm install -g https://github.com/firebase/firebase-tools.git#ll-fixemu
๋ ์ด๋ป์ต๋๊น?
@laurenzlong
npm uninstall -g firebase-tools && npm install -g https://github.com/firebase/firebase-tools.git#ll -fixemu
๋๋ ์ด๋ฏธ ๊ทธ๊ฒ์ ์๋ํ๋ค.
๋ถ๋ช ํ https://github.com/firebase/firebase-tools.git#ll -fixemu๊ฐ ๋๋ฅผ ์ํด ์์ ํฉ๋๋ค.
$ yarn global remove firebase-tools
yarn global v1.3.2
[1/2] Removing module firebase-tools...
[2/2] Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
โจ Done in 3.91s.
$ yarn global add https://github.com/firebase/firebase-tools.git\#ll-fixemu
yarn global v1.3.2
[1/4] ๐ Resolving packages...
warning https://github.com/firebase/firebase-tools.git#ll-fixemu > universal-analytics > [email protected]: Use uuid module instead
[2/4] ๐ Fetching packages...
[3/4] ๐ Linking dependencies...
[4/4] ๐ Building fresh packages...
success Installed "[email protected]" with binaries:
- firebase
โจ Done in 11.73s.
$ firebase --version
3.17.2
$ firebase serve --only functions
=== Serving from '/Users/[USERNAME]/dev/projects/[PROJECT NAME]'...
i functions: Preparing to emulate functions.
โ functions: createUrl: http://localhost:5000/[PROJECT NAME]/us-central1/createUrl
โ functions: getUrl: http://localhost:5000[PROJECT NAME]us-central1/getUrl
ํ์ฌ ๋ ธ๋ v6.11.5๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. @mono0926 ์๋ง๋ ๊ทธ๊ฒ๊ณผ ๊ด๋ จ์ด ์์ต๋๊น?
@rafasoares
ํ์ฌ ๋ ธ๋ v6.11.5๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. @mono0926 ์๋ง๋ ๊ทธ๊ฒ๊ณผ ๊ด๋ จ์ด ์์ต๋๊น?
๊ฐ์ ๋ฒ์ ์ ๋ ธ๋๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค ๐ค
@mono0926 ๋ค, ๊ทธ๋ฅ ์ถ์ธกํ์ต๋๋ค. ๋ฐฉ๊ธ ์ต์ ์ ์ฌ์ฉํด ๋ณด์๊ณ ์๋ํ์ต๋๋ค.
์ ์ญ ์ข ์์ฑ์ ์ฒ ์ ํ ์ ๋ฆฌํ๊ณ ์บ์๋ฅผ ์ ๋ฆฌํ์ญ์์ค(๋ํ ํ๋ก์ ํธ์ ๋ก์ปฌ ์ข ์์ฑ์ ๋ค์ ๋น๋ํด ๋ณด์ญ์์ค). ์ค๋ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋์ ์ฌ๋ฌ ๋ฒ ํด๋ณด์๋๋ฐ ๋์์ด ๋์์ ์๋ ์์ต๋๋ค.
@rachelmyers @laurenzlong
npm install -g https://github.com/firebase/firebase-tools.git#ll-fixemu
์๋ํ ํ ์ค๋ฅ ์ธ๋ถ ์ ๋ณด๊ฐ ๋ณ๊ฒฝ๋ ๊ฒ์ ์์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ์ ์ฝ๋์์ ์๋ฌ๊ฐ ๋์ ์์ ํ๋๋ ์๋ฌ๊ฐ ํด๊ฒฐ๋๋ค์ ๐
[email protected]
๋ฅผ ์ฌ์ฉํ๋ฉด ์ฝ๋๋ฅผ ์์ ํ์ง ์๊ณ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ง ์์ต๋๋ค.
๊ทธ๋์ ๋์ค์ ๋ง์๋๋ฆฌ์ฃ . ๋ฌธ์ ์ธ๋ถ์ฌํญ์ ์กฐ์ฌํ์ต๋๋ค.
@mono0926 ์ฝ๋์์ ๋ณ๊ฒฝํ ์ฌํญ์ ๊ณต์ ํ์๊ฒ ์ต๋๊น? Firebase์ ๊ด๋ จ๋ ๊ฒ์ด์๋์?
@rachelmyers @laurenzlong
๋๋ ๊ทธ๊ฒ์ ์กฐ์ฌํ๊ณ ๋๋ ์์ ์ ์์ ๋์ต๋๋ค.
์ด ์ฝ๋๋ก,
import * as functions from 'firebase-functions';
import * as util from 'util';
console.error(`environment: ${util.inspect(functions.config().environment.project_id)}`);
์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
TypeError: Cannot read property 'project_id' of undefined
ํ์ง๋ง ์ด ์ฝ๋๋ฅผ ์ฌ์ฉํ๋ฉด
import * as functions from 'firebase-functions';
import * as util from 'util';
console.error(`environment: ${util.inspect(functions.config().environment)}`);
์ด ๋ก๊ทธ๊ฐ ์ธ์๋ฉ๋๋ค.
info: environment: { project_id: 'development' }
์ต์ ๋ฒ์ ์์ project_id
of functions.config().environment
์ ์ก์ธ์คํ ์ ์๋ ์ด์ ๋ ๋ฌด์์
๋๊น?
[email protected]
$ ์๋์ $ project_id
of functions.config().environment
์ ์ก์ธ์คํ ์ ์์์ต๋๋ค.
๋๋ ์ด๊ฒ์ด ์ด ๋ฌธ์ ์ ๋ ๋ค๋ฅธ ๋ฌธ์ ๋ผ๋ ๊ฒ์ ์๊ณ ์์ต๋๋ค.
์ฝ๋์์ ๋ณ๊ฒฝํ ์ฌํญ์ ๊ณต์ ํ์๊ฒ ์ต๋๊น? Firebase์ ๊ด๋ จ๋ ๊ฒ์ด์๋์?
์์๋ก project_id
๊ฐ์ ํ๋์ฝ๋ฉํ์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์์ผ๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํด ์ฃผ์
จ์ผ๋ฉด ํฉ๋๋ค.
ํจ์๋ฅผ ๋ฐฐํฌํ์ ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ง ์์ต๋๋ค.
@The-Alchemist ์ ๋ ํ์ธํฉ๋๋ค: 3.16.0์ผ๋ก ๋ค์ด๊ทธ๋ ์ด๋ํ๋ฉด ์ค๋ฅ๊ฐ ์์ ๋์์ต๋๋ค!
npm install -g [email protected]
์ ๋ macOS High Sierra 10.13.2๋ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ๊ณ ์ ๊ถํ์ผ๋ก ์ค์น ํ๋ก๊ทธ๋จ์ด ์ค์นํ ๋ ธ๋ v8.9.4: https://docs.npmjs.com/getting-started/fixing-npm-permissions.
Windows์ [email protected] ์๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
๋๋ ์ป๋ค :
+ [email protected]
updated 1 package in 50.957s
(xenial)marcus<strong i="6">@localhost</strong>:~/app$ firebase serve --only functions
=== Serving from '/home/marcus/app'...
โ functions: Cannot start emulator. Error: Cannot find module '/usr/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary/grpc_node.node'
๋ง์ปค์ค: --only functions
(๋ณต์ํ)
2018๋
1์ 20์ผ ํ ์์ผ ์คํ 12:44 Marcus Hitchins [email protected]
์ผ๋ค:
๋๋ ์ป๋ค :
- [email protected]
50.957์ด์ 1๊ฐ ํจํค์ง ์ ๋ฐ์ดํธ
(xenial) marcus@localhost :~/app$ firebase serve --only ๊ธฐ๋ฅ=== '/home/marcus/app'์์ ๊ฒ์ ์ค...
์ค๋ฅ: ๋ฐฐํฌํ ๋์์ ์ดํดํ ์ ์์ต๋๋ค. --only ๋๋ --except ํ๋๊ทธ๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ ์ ํจํ ๋์์ ์ง์ ํ๋์ง ํ์ธํ์ญ์์ค. ๊ทธ๋ ์ง ์์ผ๋ฉด firebase.json์ ํ์ธํ์ฌ ํ๋ก์ ํธ๊ฐ ์ํ๋ ๊ธฐ๋ฅ์ผ๋ก ์ด๊ธฐํ๋์๋์ง ํ์ธํ์ธ์.
โ
์ด ์ค๋ ๋์ ๊ฐ์ ํ๊ธฐ ๋๋ฌธ์ ์ด ๋ฉ์์ง๋ฅผ ๋ฐ๊ณ ์์ต๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/firebase/firebase-tools/issues/609#issuecomment-359200751 ,
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/AAAD_tJH6ez89mjEZVdJbPVMDqeKym76ks5tMlAQgaJpZM4Rj8M0
.
@mono0926 ์ฐ๋ฆฌ๋ ์๋ฎฌ๋ ์ดํฐ ๋ด๋ถ์์ ์ฌ์ฉ์ ์ ์ ๊ตฌ์ฑ ๊ฐ์ ์ง์ํ์ง ์์์ต๋๋ค. ๋ณ์๊ฐ .runtimeconfig.json์ ์ ์ฅ๋๊ณ ์ก์ธ์คํ ์ ์๋๋ก ํจ์ ํด๋ ๋ด์์ "firebase functions:config:get > .runtimeconfig.json"์ ์คํํด์ผ ํฉ๋๋ค. ์๋ฎฌ๋ ์ดํฐ.
@marcus7777 https://github.com/firebase/firebase-tools/issues/442 ์์ ์บก์ฒํ ๋ณ๋์ ๋ฌธ์ ๋ผ๊ณ ์๊ฐํฉ๋๋ค.
์๋ ๋ณด๊ณ ๋ ์ค๋ฅ๊ฐ v.3.17.3์์ ์์ ๋์์ผ๋ฏ๋ก ์ง๊ธ ์ด ๋ฌธ์ ๋ฅผ ๋ซ์ต๋๋ค.
์ด๊ฒ์ด ์ผ๋ง๋ ๋นจ๋ฆฌ ์ฒ๋ฆฌ๋์๋์ง ๋๋์ต๋๋ค. ๋ฉ์ง ์ํ @laurenzlong. ๐
@laurenzlong
๋ณ์๊ฐ .runtimeconfig.json์ ์ ์ฅ๋๊ณ ์๋ฎฌ๋ ์ดํฐ์์ ์ก์ธ์คํ ์ ์๋๋ก ํจ์ ํด๋ ๋ด์์ "firebase functions:config:get > .runtimeconfig.json"์ ์คํํด์ผ ํฉ๋๋ค.
๋ด๊ฐ ์ฐธ์กฐ. ์ด ์ ๋ณด๋ฅผ ์ฐ๋ ๊ฒ์ ์์์ต๋๋ค.
functions/.runtimeconfig.json
์
๋๋ค.
{
"environment": {
"project_id": "development"
}
}
v3.16.0 ๋ฏธ๋ง์์๋ functions.config().environment. project_id
์ ์ ๊ทผํ ์ ์์์ง๋ง ์ต์ ๋ฒ์ (v3.17.3)์์๋ ์ ๊ทผํ ์ ์์ต๋๋ค.
@mono0926 ์ด์ ๋ํ ์ ๋ฌธ์ ๋ฅผ ์ด โโ์ ์์ต๋๊น? ๋ํ ์ฌ์ฉ ์ค์ธ firebase-functions์ ๋ฒ์ ์ ํฌํจ์ํค์ญ์์ค.
@laurenzlong
์ด์ ๋ํ ์ ๋ฌธ์ ๋ฅผ ์ด โโ์ ์์ต๋๊น? ๋ํ ์ฌ์ฉ ์ค์ธ firebase-functions์ ๋ฒ์ ์ ํฌํจ์ํค์ญ์์ค.
์, ๋ฌธ์ ๋ฅผ ์ด์์ต๋๋ค ๐ : https://github.com/firebase/firebase-tools/issues/629
3.17.4๋ก ์ ๋ฐ์ดํธํ๋ฉด ์ฌ์ ํ ๋ค์์ ์ป์ต๋๋ค.
sudo npm install -g firebase-tools
[sudo] password for marcus:
npm WARN deprecated [email protected]: Use uuid module instead
/usr/bin/firebase -> /usr/lib/node_modules/firebase-tools/bin/firebase
+ [email protected]
updated 4 packages in 555.594s
(xenial)marcus<strong i="6">@localhost</strong>:~$ cd app/
(xenial)marcus<strong i="7">@localhost</strong>:~/app$ firebase serve --only functions
=== Serving from '/home/marcus/Downloads/deko-app'...
โ functions: Cannot start emulator. Error: Cannot find module '/usr/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary/grpc_node.node'
(xenial)marcus<strong i="8">@localhost</strong>:~/app$
#442๋ฅผ ์๋ํ์ง๋ง ์ด์ด ์์์ต๋๋ค.
์ถ์ . xenial(Linux)์์ ์คํ
@marcus7777 ๊ทํ๊ฐ ์ง๋ฉดํ ๋ฌธ์ ๋ ์ด ๋ฌธ์ ์ ๊ด๋ จ์ด ์์ต๋๋ค. firebase-tools๋ฅผ ์ ๊ฑฐํ๊ณ ๋ค์ ์ค์นํด ๋ณด์ญ์์ค. ์๋ํ์ง ์์ผ๋ฉด ์ ๋ฌธ์ ๋ฅผ ์ฝ๋๋ค.
๋ํ ์๋ฎฌ๋ ์ดํฐ์ ๋ก์ปฌ ์ํ๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ์ญ์ ํ์ต๋๋ค.
$HOME/.config/configstore/@google-cloud/functions-emulator/.functions.json
๋ฐ ์ ์ฌํ ํ์ผ.
๊ฐ์ฌ
์๋ ํ์ธ์,
[email protected]์์๋ ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค.
@rafasoares ๊ฐ ์ธ๊ธํ ๊ฒ์ฒ๋ผ ๋ค์ ์ค์ ์ถ๊ฐํ๋ฉด ๋ฌธ์ ๊ฐ ๋ํ๋ฉ๋๋ค.
admin.initializeApp(functions.config().firebase);
์ด๊ฒ์ ๋ด๊ฐ ์ป๋ ์ค๋ฅ์ ๋๋ค.
โ functions yarn run shell
yarn run v1.5.1
$ yarn run build && firebase experimental:functions:shell
$ tsc
i functions: Preparing to emulate functions.
โ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
โ functions: Error from emulator. Error occurred while parsing your function triggers. Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder.
Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function.
at init (/Volumes/HDD/carlosbernal/Dropbox/Wanttu/Futbol/backend/functions/node_modules/firebase-functions/lib/config.js:55:15)
at Object.config (/Volumes/HDD/carlosbernal/Dropbox/Wanttu/Futbol/backend/functions/node_modules/firebase-functions/lib/config.js:29:9)
at Object.<anonymous> (/Volumes/HDD/carlosbernal/Dropbox/Wanttu/Futbol/backend/functions/lib/index.js:5:35)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
No functions emulated.
โจ Done in 11.64s.
๋ํ [email protected]
๋ก ๋ค์ด๊ทธ๋ ์ด๋ํ๋ฉด ์
ธ์ ์ก์ธ์คํ ์ ์์ง๋ง ์ ์ค๋ฅ๊ฐ ๋ํ๋ฉ๋๋ค.
โ functions yarn run shell
yarn run v1.5.1
$ yarn run build && firebase experimental:functions:shell
$ tsc
i functions: Preparing to emulate functions.
โ functions: Error from emulator. TypeError: Cannot read property 'split' of undefined
โ functions: addMessage
firebase >
@laurenzlong ๋ด๊ฐ ๋์น ๊ฒ์ด ์์ต๋๊น?
@BernalCarlos ์ค๋ฅ ๋ฉ์์ง์์ ์ ์ ์๋ฏ์ด ์ต์ firebase-functions ๋ฒ์ ์ธ์ง ํ์ธํ์ญ์์ค. ํจ์ ๋๋ ํ ๋ฆฌ์์ ๋ค์์ ์คํํ์ญ์์ค: `npm i --save firebase -functions@latest '
๊ทธ๋ฐ ๋ค์ functions/package.json์ firebase-functions 0.8.1์ด ์์ด์ผ ํฉ๋๋ค.
@laurenzlong ์ด๋ฏธ ์ต์ ๋ฒ์ ์ firebase-functions๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค. ์ด๊ฒ์ ๋ด package.json์ ๋๋ค.
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "yarn run build && firebase serve --only functions",
"shell": "yarn run build && firebase experimental:functions:shell",
"start": "yarn run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^5.9.1",
"firebase-functions": "^0.8.1"
},
"devDependencies": {
"tslint": "^5.9.1",
"typescript": "^2.7.2"
},
"private": true
}
yarn.lock์๋ ๋ค์๋ ์์ต๋๋ค.
...
firebase-functions@^0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/firebase-functions/-/firebase-functions-0.8.1.tgz#a42fe6d243862c406af16e1c16b1d0a81ec24c03"
dependencies:
"@types/express" "^4.0.33"
"@types/jsonwebtoken" "^7.1.32"
"@types/lodash" "^4.14.34"
"@types/sha1" "^1.1.0"
express "^4.0.33"
jsonwebtoken "^7.1.9"
lodash "^4.6.1"
sha1 "^1.1.1"
...
firebase-admin@^5.9.1:
version "5.9.1"
resolved "https://registry.yarnpkg.com/firebase-admin/-/firebase-admin-5.9.1.tgz#1edf6248d014063f0e473f84fe9d63df18e53807"
dependencies:
"@firebase/app" "^0.1.10"
"@firebase/database" "^0.1.11"
"@google-cloud/firestore" "^0.12.0"
"@google-cloud/storage" "^1.6.0"
"@types/google-cloud__storage" "^1.1.7"
"@types/node" "^8.0.53"
faye-websocket "0.9.3"
jsonwebtoken "8.1.0"
node-forge "0.7.1"
๊ทธ๋ฌ๋ ๋ฌธ์ ๋ ์ฌ์ ํ ์กด์ฌํฉ๋๋ค.
package.json์ ๊ณต์ ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ํ๋ก์ ํธ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ๊ฐ ๋ฌด์์ธ์ง ์๋ ค์ฃผ์ค ์ ์์ต๋๊น? ์์ง ๋ชจ๋ ธ ์ ์ฅ์๋ฅผ ์ง์ํ์ง ์์ผ๋ฏ๋ก functions/node_modules/firebase-functions ํด๋๊ฐ ์์ด์ผ ํฉ๋๋ค.
๋ฌผ๋ก @laurenzlong ์ด ๋ด ํ๋ก์ ํธ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ๋ node_modules ํด๋ ๋๋ฌธ์ ์๋นํ ํฝ๋๋ค.
[email protected] (์: firebase CLI) ๋ฌธ์ ๊ฐ ๋ค์ ๋ํ๋๋ฉฐ ๊ธฐ๋ฅ๊ณผ ์ง์ ๊ด๋ จ์ด ์์ง๋ง 3.17.4๋ก ๋กค๋ฐฑํ๋ฉด ์๋ฎฌ๋ ์ด์
์ด ์๋ํฉ๋๋ค.
firebase-tools repo: firebase/firebase-tools#691์์ ํด๋น ๋ฌธ์ ๋ฅผ ์ด์์ต๋๋ค.
@Rulsky with [email protected] , ๋งค์ฐ ๊ฐ๋จํ ๊ธฐ๋ฅ์ ๋ํด ๋ค๋ฅธ ์ค๋ฅ๋ก ์คํจํฉ๋๋ค.
// index.ts
import * as fbAdmin from "firebase-admin";
import * as fbFunctions from "firebase-functions";
fbAdmin.initializeApp(fbFunctions.config().firebase);
export const addMessage = fbFunctions.https.onRequest((request, response) => {
const original = request.query.text;
response.send(original);
});
์ค๋ฅ:
โ functions yarn run shell
yarn run v1.5.1
$ yarn run build && firebase experimental:functions:shell
$ tsc
i functions: Preparing to emulate functions.
โ functions: Failed to emulate addMessage
No functions emulated.
โจ Done in 12.71s.
๋ํ Firebase CLI๊ฐ ์คํ๋ ๋ ๋ก๊ทธ ํ์ผ์ด ์์ฑ๋์ง๋ง ํด๋น ํ์ผ์ ์ฆ์ ์ญ์ ๋๋ ๊ฒ์ ํ์ธํ์ต๋๋ค. ์ด ๋ก๊ทธ ํ์ผ์ด ์ญ์ ๋์ง ์๋๋ก ํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
@BernalCarlos ํ๋ก์ ํธ์ functions
๋๋ ํ ๋ฆฌ์ ์๋น์ค ๊ด๋ฆฌ์ ํค๋ฅผ ๋ฃ์์ต๋๊น? ๊ทธ๋ฆฌ๊ณ ์
ธ์์ GOOGLE_APPLICATION_CREDENTIALS ์ ์ญ ๋ณ์๋ฅผ ๋ด๋ณด๋์ต๋๊น?
https://firebase.google.com/docs/functions/local-emulator ๊ฐ ์๋ํ๋๋ก ํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค.
Firebase ์ธ์ฆ ๋๋ ๊ธฐํ Google API๋ฅผ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ์ค์ ๋ก GOOGLE_APPLICATION_CREDENTIALS๋ฅผ ์ค์ ํ ํ์๊ฐ ์์ต๋๋ค. ๊ทธ๋์ @BernalCarlos ๊ทํ์ ๋ฌธ์ ๋ https://github.com/firebase/firebase-tools/issues/691 ๊ณผ ๋์ผํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ์ด ๋ฌธ์ ๋ฅผ ์์ ํ๊ณ ํด๋น ๋ฌธ์ ์ ์ฐ๊ฒฐํ์ต๋๋ค.
const app = admin.initializeApp(functions.config().firebase);
๋ฅผ ํฌํจํ ๋ CLI๊ฐ ์์ฑํ๊ณ ์๋ํ์ง ์๋ ๊ธฐ๋ฅ๋ง ์๋ ๊นจ๋ํ ํ๋ก์ ํธ๊ฐ ์์ต๋๋ค. ํ๋ก์ ํธ๋ ๋ค์์ผ๋ก ์ค์ ๋์์ต๋๋ค.
```
"์ข
์์ฑ": {
"firebase-admin": "~5.8.1",
"firebase-functions": "^0.8.1"
}
````
@Jhony0311 ๋น์ ๋ #691์ ์ํฅ์ ๋ฐ์์ ๊ฒ์ ๋๋ค.
firebase deploy --only functions
๋ ์ฌ์ฉํ ์ ์์ง๋ง firebase serve --only functions
๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.
"npm run serve"๋ฅผ ์คํํ ํ์๋ ๊ณ์ ๋ก๋๋ฉ๋๋ค.
i ๊ธฐ๋ฅ: ๊ธฐ๋ฅ ์๋ฎฌ๋ ์ด์
์ค๋น.
๊ฒฝ๊ณ : Node.js v10.5.0์ ์ฌ์ฉ ์ค์ด์ง๋ง Google Cloud Functions๋ v6.11.5๋ง ์ง์ํฉ๋๋ค.
โ ๊ธฐ๋ฅ: getSomeData ์๋ฎฌ๋ ์ด์
์คํจ
i ๊ธฐ๋ฅ: HTTPS ๊ธฐ๋ฅ์ ์ฐพ์ ์ ์์ต๋๋ค. ๋ค๋ฅธ ์ ํ์ ๊ธฐ๋ฅ์ ์๋ฎฌ๋ ์ดํธํ๋ ค๋ฉด Firebase functions:shell ์ ์ฌ์ฉํ์ธ์.
firebase version: 3.19.3
์ด๊ฒ์ ๋ด ์ฝ๋์ ๋๋ค.
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.getSomeData = functions.https.onRequest((req, res) => {
admin.firestore().doc('feedback/d8pGxmML5ZKLYEy5jyhm').get()
.then(doc => res.send(doc.data()))
.catch(err => res.status(500).send(err));
});
์ด๋ค ์ ์?
์๋
ํ์ธ์, ๋
ธ๋ 10์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
์ด์ ๋ฒ์ ์ ์ฌ์ฉํ์ญ์์ค. ์๋ฅผ ๋ค์ด ๋ฒ์ 8.
2018๋
7์ 4์ผ 01:46 +0200, Nicolas Sturm [email protected] ์ด ๋ค์๊ณผ ๊ฐ์ด ์ผ์ต๋๋ค.
firebase deploy --only ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์์ง๋ง firebase serve --only ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
"npm run serve"๋ฅผ ์คํํ ํ์๋ ๊ณ์ ๋ก๋๋ฉ๋๋ค.
i ๊ธฐ๋ฅ: ๊ธฐ๋ฅ ์๋ฎฌ๋ ์ด์ ์ค๋น.
๊ฒฝ๊ณ : Node.js v10.5.0์ ์ฌ์ฉ ์ค์ด์ง๋ง Google Cloud Functions๋ v6.11.5๋ง ์ง์ํฉ๋๋ค.
โ ๊ธฐ๋ฅ: getSomeData ์๋ฎฌ๋ ์ด์ ์คํจ
i ๊ธฐ๋ฅ: HTTPS ๊ธฐ๋ฅ์ ์ฐพ์ ์ ์์ต๋๋ค. ๋ค๋ฅธ ์ ํ์ ๊ธฐ๋ฅ์ ์๋ฎฌ๋ ์ดํธํ๋ ค๋ฉด Firebase functions:shell ์ ์ฌ์ฉํ์ธ์.
Firebase ๋ฒ์ : 3.19.3
์ด๊ฒ์ ๋ด ์ฝ๋์ ๋๋ค.
'์๊ฒฉํ ์ฌ์ฉ';const ํจ์ = require('firebase-functions');
const ๊ด๋ฆฌ์ = ์๊ตฌ('ํ์ด์ด๋ฒ ์ด์ค ๊ด๋ฆฌ์');admin.initializeApp();
export.getSomeData = functions.https.onRequest((req, res) => {
admin.firestore().doc('ํผ๋๋ฐฑ/d8pGxmML5ZKLYEy5jyhm').get()
.then(doc => res.send(doc.data()))
.catch(err => res.status(500).send(err));
});
์ด๋ค ์ ์?
โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ฑฐ๋ GitHub์์ ๋ณด๊ฑฐ๋ ์ค๋ ๋๋ฅผ ์์๊ฑฐํ์ธ์.
๋ค๋ฅธ ์ฌ๋๋ค์๊ฒ ๋์์ด ๋๋ ๊ฒฝ์ฐ Dialogflow์ fulfillment
๋ฅผ ์ฌ์ฉํ๊ณ ์ฝ๋๋ฅผ ๋ก์ปฌ์์ ํธ์ง ๋ฐ ํ
์คํธํ๋ ค๊ณ ํ์ต๋๋ค. ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๊ทธ๊ฒ์ ํด๊ฒฐ ํ ๊ฒ์ @rafasoares ๊ฐ ๋งํ ๊ฒ๊ณผ ์ ์ฌํ์ต๋๋ค.
์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์์ฑ๋ firebase init
๊ฐ ์๋ ์ฌ์ฉ๋ package.json Dialogflow ๋ฅผ ๋ณต์ฌํด์ผ ํ์ต๋๋ค. ๋ฒ์ ๋ฌธ์ ์ธ ๊ฒ ๊ฐ์ต๋๋ค.
๋๋ ๋๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ๋ค์ํ ๋ฐฐํฌ ๋จ๊ณ์์ ํ๊ฒฝ ๋ณ์๋ฅผ ์ฌ์ฉํ์ง ์๊ณ JSON ๊ตฌ์ฑ ํ์ผ๋ง ์ฌ์ฉํ ๊ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค. ์์ ์ฌํญ์ ๋ณด๊ณ ์ถ์ต๋๋ค. npm์ ์คํํด๋ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์ง ์์ต๋๋ค.
์ ๊ฒฝ์ฐ์๋ firebase deploy
๋ฅผ ๋จผ์ ์คํํ ๋ค์ firebase serve
๋ฅผ ์คํํ์ฌ ๋ฒ๊ทธ๋ฅผ ์์ ํ๊ณ ๋ฒ๊ทธ๊ฐ ์ฌ๋ผ์ก์ต๋๋ค.
๋ชจ๋ firebase-tools, firebase-admin, firebase-functions์ ์ต์ ๊ฒ์ผ๋ก ์ ๋ฐ์ดํธํ์ต๋๋ค.
"dependencies": {
"firebase-admin": "^7.3.0",
"firebase-functions": "^2.3.0",
"googleapis": "^32.0.0",
"mailgun-js": "^0.18.0",
"moment": "^2.20.1",
"request": "^2.81.0",
"request-promise": "^4.2.1"
},
"private": true,
"devDependencies": {
"firebase-functions-test": "^0.1.2",
"firebase-tools": "^6.8.0",
"mocha": "^5.2.0",
"rewire": "^4.0.1",
"sinon": "^6.0.0",
"underscore": "^1.9.1"
},
๊ทธ๋ฌ๋ Firebase ๊ธฐ๋ฅ ์ ธ์ ์คํํ๋ ค๊ณ ํ ๋ ์ฌ์ ํ ์ด ์ค๋ฅ๊ฐ ํ์๋ฉ๋๋ค.
i functions: Preparing to emulate functions.
โ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
โ functions: Error from emulator. Error occurred while parsing your function triggers.
@Randyanto ์๋
ํ์ธ์, ๋ช
ํํ ๋ต๋ณ์ ๋๋ฆด ์๋ ์์ง๋ง ๋ช ๊ฐ์ง ๋จ์๋ฅผ ๋๋ฆด ์๋ ์์ต๋๋ค. ๋๋ ๊ฐ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์ ๊ฒฝ์ฐ์๋ require('firebase')
์ ๋๋ก ์๋ํ์ง ๋ชปํ์ต๋๋ค. ๊ทธ๋์ ' [email protected] ' ๋ค์ด๊ทธ๋ ์ด๋๋ฅผ ์๋ํ์ต๋๋ค.
npm install --save [email protected]
ํ์ต๋๋ค. ๋ง์นจ๋ด ๋๋ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์๋ค.
Firebase ๋๋ ๊ธฐํ ๊ธฐ๋ฅ๊ณผ ๊ด๋ จ๋ ๋ฌธ์ ๊ฐ ์์ ์ ์์ต๋๋ค.
๊ฐ์ง๊ณ ์๋ ๊ฐ ๋ฒ์ ์ข
์์ฑ์ ํ์ธํ์ญ์์ค. ํ์ด์ ๋น๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
firebase serve --only functions
๋์ functions ๋๋ ํ ๋ฆฌ ๋ด๋ถ์์npm run serve
๋ฅผ ์คํํด ๋ณด์ญ์์ค. ์ด๊ฒ์ package.json ํ์ผ์ด ๊ตฌ์ฑ๋ ๋ฐฉ์์ ๋ฐ๋ผ ์๋ํ ์๋ ์๊ณ ์๋ํ์ง ์์ ์๋ ์์ต๋๋ค.