我創建了一個僅包含 HTML 檔案的專案,我想將它部署在 Heroku 上。所以我創建了一個虛擬后端來部署在 Heroku 上,但是當我在 localhost 上運行它時,它會顯示一個錯誤,即沒有這樣的檔案或目錄
錯誤圖片:

var express = require('express');
var app = express();
var path = require('path');
app.use(express.static(path.join(__dirname)));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname 'project.html'));
});
// add other routes below
app.get('/Vaccine2', function(req, res) {
res.sendFile(path.join(__dirname 'Vaccine2.html'));
});
app.get('/hospital', function(req, res) {
res.sendFile(path.join(__dirname 'hospital.html'));
});
app.listen(process.env.PORT || 3000);
uj5u.com熱心網友回復:
\在檔案名中添加反斜杠。
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname '\project.html'));
});
// add other routes below
app.get('/Vaccine2', function(req, res) {
res.sendFile(path.join(__dirname '\Vaccine2.html'));
});
app.get('/hospital', function(req, res) {
res.sendFile(path.join(__dirname '\hospital.html'));
});
uj5u.com熱心網友回復:
首先在Git中洗掉一個分支
rm -rf .git
然后在專案上創建一個 src 目錄
并更改您的代碼
這:
app.use('/src', express.static(path.join(__dirname)));
對此:
app.use('/src', express.static(path.join(__dirname '/src')));
轉到您的 package.json 檔案并添加您的 node.js 版本,例如:
"engines": {
"node": "14.x"
}
并嘗試再次部署您的網站
git add .
git commit -m "Added a Procfile."
heroku login
Enter your Heroku credentials.
...
heroku create
Creating arcane-lowlands-8408... done, stack is cedar
http://arcane-lowlands-8408.herokuapp.com/ | git@heroku.com:arcane-
lowlands-8408.git
Git remote heroku added
git push heroku main
...
-----> Node.js app detected
...
-----> Launching... done
http://arcane-lowlands-8408.herokuapp.com deployed to Heroku
您可以查看一些Recorses:
Heroku 托管
首先要確保你在heroku中正確輸入了所有評論。如果您知道與否,請隨時發回訊息。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/419573.html
標籤:
