2
3

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.

express.jsアプリをFirebase Functionsにデプロイする

Posted at

前回:express.jsアプリをAWS CloudFormationでデプロイする

前提

  • Googleアカウント
  • firebaseプロジェクト
  • firebase-tools

プロジェクト初期化

$ firebase init functions

expressアプリ追加

  • firebase-functionsの読み込み
  • functions.https.onRequestイベントハンドラにアプリを渡す
  • exportする
// index.js
const functions = require('firebase-functions');
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  console.log(req.method, req.url);
  res.send({ status: true });
});

const api = functions.https.onRequest(app);

module.exports = { api };

ごくごく簡単なアプリ

確認

エミュレータ起動

$ firebase emulators:start

上のアプリの場合はhttp://localhost:5001/<YOUR PROJECT ID>/<REGION>/apiといったURLで確認できる。exportsに渡した名前がそのままpathになるようだ。

デプロイ

  • Firebase Functionsは従量課金(Blaze)プランでないとデプロイできない
$ firebase deploy --only functions

その他

  • 途中でつまづくようなところはなし。AWS CloudFormation(lambda + API Gateway)より簡単な印象。
  • 個人でさくっとなにかしたいならFirebaseがよさそう。

参考

2
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?