[英]Node.js Express Server on Forwarded Localhost - Not Responding
[英]Node.js express server runs on localhost but having issues on Heroku host
我的 express.js 代碼有問題,它在本地主機上正常運行,但在 Heroku 上對我不起作用,我認為存在某種錯誤,這是我的代碼和我遇到的錯誤
服務器.js
const express = require("express")
const app = express()
let PORT = process.env.PORT || 3000
//for __dirname
const path = require('path')
//Render css if it wasnt included in html file
app.use(express.static('./Pages'));
//redirect link to home page
app.get('/', function(request, response){
response.redirect('/home')
})
//home page response
app.get('/home', function(request, response){
response.sendFile(path.join(__dirname, './Pages', 'home.html'))
})
//about page response
app.get('/about', function(request, response){
response.sendFile(path.join(__dirname, "./Pages", "about.html"))
})
//listening to port
app.listen(PORT, function(){
console.log("Server is online on port: " + PORT)
})
在 Heroku 上,它給出一個“應用程序錯誤”,它記錄了它正在運行的端口,所以我可以告訴代碼正在運行,所以它不是我的 Procfile 的問題,它也有一個“favicon.io”錯誤,我不知道怎么解決
這是我的 Heroku 日志,其中包含錯誤
at=error code=H14 desc="No web processes running" method=GET path="/" host=candy-lounge.herokuapp.com request_id=f550b1f8-6152-4a01-97b3-81fec080fed5 fwd="(seems like an ip so i deleted it)" dyno= connect= service= status=503 bytes= protocol=https
2020-12-10T17:35:47.907477+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=candy-lounge.herokuapp.com request_id=cf93d0a2-0d01-4952-b037-92cc733a9dd1 fwd="(seems like an ip so i deleted it)" dyno= connect= service= status=503 bytes= protocol=https
所以我解決了這個問題,這個問題真的很奇怪但很簡單,不知何故 heroku 對文件名是大小寫敏感的,所以它只是運行服務器,但找不到 server.js 要求的任何文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.