我正在尝试遵循以下演练:https://www.youtube.com/watch?v=LOeioOKUKI8,用于在Firebase上设置节点应用托管。
我无法使本地版本正常工作(一切正常部署)
我已经使用CLI建立了项目,一切都很好。在演练中,他从未在本地加载完成的项目。这是否意味着您无法在本地处理某些事情?
这是我在index.js中运行的代码,并在firebase.json中重写设置
firebase.json
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [{
"source": "**",
"function": "app"
}]
}
}
index.js(在functions /目录中)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const firebaseAdmin = admin.initializeApp(
functions.config().firebase
);
const app = express();
// Products
app.get('/products', (request, response) => {
response.json({
"products": [{
"type": "Type 1",
"title": "Product 1"
}]
});
});
// Main export of app
exports.app = functions.https.onRequest(app);
当我使用firebase serve
我在终端机上明白了
✔ functions: Using node@8 from host.
✔ functions: Emulator started at http://localhost:5001
i functions: Watching "/Users/justbane/_FireBase/relatables_app/functions" for Cloud Functions...
i hosting: Serving hosting files from: public
✔ hosting: Local server: http://localhost:5000
⚠ Default "firebase-admin" instance created!
i functions: HTTP trigger initialized at http://localhost:5001/relatables-d98b3/us-central1/app
但是当我访问本地地址http://localhost:5000/products
我在浏览器中看到Cannot GET /relatables-d98b3/us-central1/app/products