Javascript 反应-firebase主机不工作

Javascript 反应-firebase主机不工作,javascript,reactjs,firebase,google-cloud-functions,firebase-hosting,Javascript,Reactjs,Firebase,Google Cloud Functions,Firebase Hosting,我正在使用react和firebase创建api 但是没有主机。Chrome浏览器需要清空缓存和强大的刷新才能获得404页面 url是 总之,我想使用react和firebase作为主机 以下是项目设置 谢谢你的建议 firebase.json { "firestore": { "rules": "firestore.rules", "indexes": "firestore.indexes.json" }, "functions": { "predeploy

我正在使用react和firebase创建api

但是没有主机。Chrome浏览器需要清空缓存和强大的刷新才能获得404页面

url是

总之,我想使用react和firebase作为主机

以下是项目设置

谢谢你的建议

firebase.json

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": [
         "npm --prefix \"$RESOURCE_DIR\" run lint"
    ],
    "source": "functions"
  },
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "/api/**",
        "function": "api"
      }
    ],
    "headers": [ {
      "source" : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
      "headers" : [ {
        "key" : "Access-Control-Allow-Origin",
        "value" : "*"
      } ]
      }, {
     "source" : "**/*.@(jpg|jpeg|gif|png)",
      "headers" : [ {
        "key" : "Cache-Control",
        "value" : "max-age=7200"
      } ]
      }, {
      "source" : "404.html",
      "headers" : [ {
        "key" : "Cache-Control",
        "value" : "max-age=300"
      } ]
    } ],
    "cleanUrls": true,
    "trailingSlash": false
  }
}
/src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import * as firebase from 'firebase';

const config = {
  apiKey: "xxxxxxxx",
  authDomain: "xxxxxxxx",
  databaseURL: "xxxxxxxx",
  projectId: "xxxxxxxx",
  storageBucket: "xxxxxxxx",
  messagingSenderId: "xxxxxxxx"
};
firebase.initializeApp(config);

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
树视图


看起来很好用。您指定希望它在firebase函数的json响应中显示
code:200
。你还期待什么吗?

我不知道为什么,但这是工作。但问题中的源已重新部署,因此无法工作。我不知道为什么,我不明白。托管有时可能需要一些时间。另外,如果您没有看到我看到的内容,您可能需要刷新浏览器缓存。谢谢您的回答。缓存似乎是正确的,我不明白。你是说它不起作用吗?你修好了吗?我不清楚现在的问题是什么。当我创建这个项目时,我在“重写”选项中得到了“是”,它被修复了。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const serviceAccount = require('./serviceAccountKey.json');
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://jp-db-2018.firebaseio.com"
});
const express = require('express');
const app = express();
const db = admin.firestore();

app.get('/getChannels', (req, res) => {
  res.json({code: 200});
});
exports.api = functions.https.onRequest(app);