facebook twitter hatena line email

「Gcp/Firebase/CloudFunctions/Basic認証」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==hostingでbasic認証の作り方== #firebase init functions function/index.js <pre> const functions = require('firebase-functions') const express = require('express')...」)
(相違点なし)

2022年11月6日 (日) 06:18時点における版

hostingでbasic認証の作り方

  1. firebase init functions

function/index.js

const functions = require('firebase-functions')
const express = require('express')
const basicAuth = require('basic-auth-connect')
const app = express()

app.all('/*', basicAuth(function(user, password) {
  return user === 'user1' && password === 'testtest';
}));
app.use(express.static(__dirname + '/static/'))
exports.app = functions.https.onRequest(app)

firebase.json

{
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "**",
        "function": "app"
      }
    ],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}
  1. firebase deploy


参考

https://qiita.com/567000/items/65f55eda8d7c6df09138

https://qiita.com/ohana/items/f334c096727740f0df4a