express、firebase functions、hostingを用いてwebアプリを製作してます
困っているのは、firebaseでホスティングされた静的ファイルをgetする際、
404が帰ってきてしまうことです
以下情報です
- localhostでは
localhost/hogehoge
にアクセスすると、react-routerでルーティングを施した
/hogehogeにアクセス可能
- webサイト
index.htmlをエントリーポイントにparcelを用いてビルドしたものをdistに出力
- expressの設定
js
1 2const app = express(); 3app.use(express.static('../../dist')); 4app.use(function(req, res) { 5 res.sendFile(path.join(__dirname, "../../dist", "index.html")) 6 }); 7 8 9export const application = functions.https.onRequest(app);
firebase.jsonの設定
json
1{ 2 "functions": { 3 "predeploy": [ 4 "npm --prefix \"$RESOURCE_DIR\" run lint", 5 "npm --prefix \"$RESOURCE_DIR\" run build" 6 ] 7 }, 8 "hosting": { 9 "public": "dist", 10 "ignore": [ 11 "firebase.json", 12 "**/.*", 13 "**/node_modules/**" 14 ], 15 "rewrites": [ 16 { 17 "source": "**", 18 "function": "application" 19 } 20 ] 21 } 22}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。