我正在嘗試使用 Google App Engine 托管我的專案,但無法顯示我的頁面。我的 package.json 看起來像這樣
"name": "final",
"version": "1.0.0",
"description": "",
"main": "index.html",
"scripts": {
"start": "node app.js"
}
我的 app.js 看起來像這樣:
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.sendFile('/index.html');
});
// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}...`);
});
當我部署時,頁面只是說 Not Found 并給我一個 404。我需要對我的 index.html 和它使用的后續 .js 檔案做些什么,還是在我部署時上傳我的整個目錄?錯誤日志給我的只是 404。
uj5u.com熱心網友回復:
您需要指定的完整路徑 index.html
const express = require('express');
const app = express();
const path = require('path');
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/index.html'));
});
// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}...`);
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/318963.html
標籤:javascript 节点.js 表达 谷歌应用引擎
上一篇:'找不到服務“%s”的api代理'%serviceAssertionError:找不到服務“datastore_v3”的api代理
