4
0

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 5 years have passed since last update.

FirebaseFunctionsで素のJSを返す

4
Last updated at Posted at 2019-11-03

実現したいこと

FirebaseFunctionsを使ってリクエスト元やパラメータに合わせたJSファイルを作り返したい

こんな風に使いたい

<script src="https://asia-northeast1-fir-functions-return-js.cloudfunctions.net/hello"></script>

Functionsの実装

functions/index.js

exports.hello = functions
  .region('asia-northeast1')
  .https.onRequest((request, response) => {
    // Using query
    const name = request.query.name || 'defaultName';
    // Return alert js
    response
      .contentType('application/javascript; charset=utf-8')
      .send(`alert('Hello ${name}')`);
  });

response.send で返してあげるだけで読み込み可能でした。

サンプル

サンプルページ

ソースコード

※自ブログからの転載です
http://akinov.hatenablog.com/entry/2019/11/03/205102

4
0
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
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?