app.use(router);
router.getpost('/test', (req, res) => {
res.send('TEST!');
});
export const api = functions.https.onRequest(app);
</pre>
===https.onCall のプロトコル仕様===
*https://firebase.google.com/docs/functions/callable-reference
*呼び出し可能なトリガー エンドポイントへの HTTP リクエストは、次のヘッダーが含まれる POST にする必要があります。
**必須: Content-Type: application/json
**省略可: Authorization: Bearer <token>:リクエストを行うログイン済みユーザーの Firebase Authentication ユーザー ID トークンです。このトークンはバックエンドで自動的に検証され、ハンドラの context で使用可能になります。トークンが有効でない場合、リクエストは拒否されます。
**省略可: Firebase-Instance-ID-Token: <iid>:Firebase クライアント SDK の FCM 登録トークンです。これには文字列を設定する必要があります。またハンドラの context で使用できます。プッシュ通知のターゲティングに使用されます。
===カスタムドメイン===
#Hostingに対してカスタムドメインを設定
#firebase.json の hosting の rewrite に functions を追加
*Functions
<pre>
import * as functions from 'firebase-functions';
import * as express from 'express';
const app: express.Express = express();
router.get('/api/test', (req, res) => {
res.send('TEST!');
});
export const apiService = functions.https.onRequest(app);
</pre>
*firebase.json
**パスもapi、公開(export)する関数も apiだと、パスにマッチしないため、別の名前にする
<pre>
"hosting": [
: 省略
"rewrites": [
{ "source": "/api/**", "function": "apiapiService"
},
{
"destination": "/index.html"
}
]
}
]
</pre>
*実行
[[File:functions_custom_domain.png|400px]]