2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Firebase CloudFunctionsで関数名に、ハイフン(-)が使えない場合の対処

Last updated at Posted at 2020-08-20

##Firebase CloudFunctionsで - があるエンドポイントを作りたいけど、やり方がわからない
express.jsを使えば特に調べずにできるが、そこまで複雑ではないので、firebaseのみで完結させたい。

頑張って調べてみることにした。

####これだと、当然エラーが出ます

exports.hello-world = functions.https.onRequest((request, response) => {
  response.json({ name: 'first' })
})

####そんなときは、ブラケット記法だと使ってみてlintでは引っかからなかったけど、firebaseにデプロイするときに弾かれる。

exports['hello-world'] = functions.https.onRequest((request, response) => {
  response.json({ name: 'first' })
})
Running command: npm --prefix "$RESOURCE_DIR" run build

> functions@ build /Users/USERNAME/Desktop/PROJECTDIR/functions
> tsc

✔  functions: Finished running predeploy script.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing functions directory for uploading...

Error: Function name "hello-world" is invalid. Function names cannot contain dashes.

なんで( ;∀;)

##結論

exports.hello = {
  world: functions.https.onRequest((request, response) => {
    response.json({ name: 'first' })
  }),
}

これが正解なのだそう。
ネストさせるみたいですね。

ブログなどの記事を見る前に、githubのissueを先に探しておけばよかったです。

##参考文献

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?