在 Google App Engine 中找不到 index.html 的 404 - 如何显示页面?
404 Not Found for index.html in Google App Engine - How to get page to show up?
我正在尝试使用 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}...`);
});
当我部署时,页面只显示“未找到”并给我一个 404。我需要对我的 index.html 和它使用的后续 .js 文件做些什么吗?部署?错误日志只给我 404。
您需要指定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}...`);
});
我正在尝试使用 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}...`);
});
当我部署时,页面只显示“未找到”并给我一个 404。我需要对我的 index.html 和它使用的后续 .js 文件做些什么吗?部署?错误日志只给我 404。
您需要指定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}...`);
});