测试后几个月,节点JS应用程序不在Heroku上工作
我已经阅读了来自不同堆栈溢出的解决方案,但不能解决问题 这个终点在几个月前在本地主机和Heroku上正常工作,但是现在它仅在本地主机上工作正常,我在尝试访问终点后才获得此错误
/strong>
'use strict';
require("dotenv").config();
require('./MongoDB/DB')
const http = require('http');
const express = require('express');
const cors = require("cors");
const mongoSanitize = require('express-mongo-sanitize');
let cookieParser = require('cookie-parser');
const app = express();
const server = http.createServer(app)
const port=process.env.PORT||5000;
const passportContol=require("./Passport/index")
app.use(cors())
app.use(cookieParser())
app.use(express.json({ limit: "1kb" }));
app.use(express.urlencoded({ extended: true,limit: "1kb"}));
app.use(
mongoSanitize({
replaceWith: '_',
}),
);
app.use(passportContol.initialize());
app.set('trust proxy', 1);
const router1=require('./Router/Account')
const router2=require('./Router/Post')
const router3=require('./Router/Request')
app.use("/",router1);
app.use("/",router2);
app.use("/",router3);
server.listen(port ,()=>console.log(`server started.... ${port}`))
package.json
{
"name": "api-campus-bet",
"version": "1.0.0",
"description": "campus-bet api for soccer betting",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js",
"dev": "nodemon server"
},
"author": "Ogbonna Chinaza",
"license": "ISC",
"dependencies": {
"axios": "^0.26.1",
"bcrypt": "^5.0.1",
"cookie": "^0.4.2",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"csurf": "^1.11.0",
"dotenv": "^16.0.0",
"express": "^4.17.3",
"express-mongo-sanitize": "^2.2.0",
"express-rate-limit": "^6.3.0",
"ioredis": "^5.0.3",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.2.9",
"passport": "^0.5.2",
"passport-local": "^1.0.0"
},
"engines": {
"node": "16.13.1"
}
}
procfile
web: node server.js
我所做的
- 我已经重新安装了nodemodule,我做了这一点,包括封装 - 洛克
- 。 (git commit -wally -empty -m“清除缓存” $ git push heroku master)
- 我删除了heroku上的整个项目,并在没有错误消息的
情况下
推出一个新项目,请我需要帮助我做错了什么
I have read up solution from different stack overflow but non solves the problem
This end point works fine on local host and heroku some month ago but now it works fine only on local host I get this error after I try to access the end point
server.js file
'use strict';
require("dotenv").config();
require('./MongoDB/DB')
const http = require('http');
const express = require('express');
const cors = require("cors");
const mongoSanitize = require('express-mongo-sanitize');
let cookieParser = require('cookie-parser');
const app = express();
const server = http.createServer(app)
const port=process.env.PORT||5000;
const passportContol=require("./Passport/index")
app.use(cors())
app.use(cookieParser())
app.use(express.json({ limit: "1kb" }));
app.use(express.urlencoded({ extended: true,limit: "1kb"}));
app.use(
mongoSanitize({
replaceWith: '_',
}),
);
app.use(passportContol.initialize());
app.set('trust proxy', 1);
const router1=require('./Router/Account')
const router2=require('./Router/Post')
const router3=require('./Router/Request')
app.use("/",router1);
app.use("/",router2);
app.use("/",router3);
server.listen(port ,()=>console.log(`server started.... ${port}`))
package.json
{
"name": "api-campus-bet",
"version": "1.0.0",
"description": "campus-bet api for soccer betting",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js",
"dev": "nodemon server"
},
"author": "Ogbonna Chinaza",
"license": "ISC",
"dependencies": {
"axios": "^0.26.1",
"bcrypt": "^5.0.1",
"cookie": "^0.4.2",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"csurf": "^1.11.0",
"dotenv": "^16.0.0",
"express": "^4.17.3",
"express-mongo-sanitize": "^2.2.0",
"express-rate-limit": "^6.3.0",
"ioredis": "^5.0.3",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.2.9",
"passport": "^0.5.2",
"passport-local": "^1.0.0"
},
"engines": {
"node": "16.13.1"
}
}
Procfile
web: node server.js
WHAT I HAVE DONE
- I have reinstall the nodemodule i did this including package-lock.json
- I have cleared heroku cache
(git commit --allow-empty -m "Purge cache"
$ git push heroku master) - I deleted the whole project on heroku and push a new one with no error message
with some other things
please I need help what have I done wrong
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题是由git引起的,其中包括一些文件,这些文件在托管节点模块和gitignore文件等托管时不应包括。我通过在本网站中使用解决方案来删除这些文件来解决问题。
remove n node_modules in vscode in vscode
This problem was caused by git it was including some files which should not be included when hosting like node module and the gitignore file. I solved the problem by using the solution in this site to remove those files.
Remove node_modules from git in vscode