繁体   English   中英

Node.js express 服务器在本地主机上运行,但在 Heroku 主机上出现问题

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM