“ URL”参数必须是类型字符串。收到未定义的
我正在尝试将我的自定义Express/Node应用程序部署到Digitalocean应用程序平台。但是在部署期间收回此错误:
这是我的软件包
{
"name": "backend",
"version": "1.0.0",
"main": "app.js",
"license": "MIT",
"dependencies": {
"bcrypt": "^5.0.1",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"jsonwebtoken": "^8.5.1",
"mysql2": "^2.3.3",
"nodemailer": "^6.7.5",
"nodemon": "^2.0.16",
"passport": "^0.5.2",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"pg": "^8.7.3",
"pg-hstore": "^2.3.4",
"sequelize": "^6.19.0",
"sequelize-cli": "^6.4.1"
},
"scripts": {
"start": "nodemon app.js",
"deploy": "node app.js"
},
"engines": {
"node": "16.15"
}
}
。 .JSON中的DB文件夹:
{
"development": {
"username": "postgres",
"password": "10300",
"database": "weblogin",
"host": "127.0.0.1",
"dialect": "postgres",
"logging": false
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"use_env_variable": "DATABASE_URL"
}
}
还添加了模型/index.js
...
sequelize = new Sequelize(process.env[config.use_env_variable], {
dialect: "postgres",
dialectOptions: {
ssl: true,
},
});
} else {
...
更新 当我运行VSCODE调试器时,它会显示出相同的错误,以防止其发送任何变量。 debugger
我不知道该错误来自哪里。
这是app.js,
const express = require("express");
const app = express();
const db = require("./db/models");
const cors = require("cors");
const passport = require("passport");
const { localStrategy, jwtStrategy } = require("./middleware/passport");
const userRoutes = require("./routes/users");
require("dotenv").config();
//middleware
app.use(express.json());
app.use(cors());
//passport
app.use(passport.initialize());
passport.use(localStrategy);
passport.use(jwtStrategy);
//routes
app.use(userRoutes);
//Not Found
app.use((req, res, next) => {
next({
status: 404,
message: "Path not found",
});
});
//Error Handling
app.use((error, req, res, next) => {
res
.status(error.status || 500)
.json({ message: error.message || "Internal Server Error" });
});
db.sequelize.sync({ alter: true });
//db.sequelize.sync({ force: true });
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log("application is running" + PORT);
});
您能帮我找出如何解决这个问题吗? 谢谢。
I am trying to deploy my custom express/node app to digitalocean app platform. But recieving this error during the deployment:
This is my package.json
{
"name": "backend",
"version": "1.0.0",
"main": "app.js",
"license": "MIT",
"dependencies": {
"bcrypt": "^5.0.1",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"jsonwebtoken": "^8.5.1",
"mysql2": "^2.3.3",
"nodemailer": "^6.7.5",
"nodemon": "^2.0.16",
"passport": "^0.5.2",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"pg": "^8.7.3",
"pg-hstore": "^2.3.4",
"sequelize": "^6.19.0",
"sequelize-cli": "^6.4.1"
},
"scripts": {
"start": "nodemon app.js",
"deploy": "node app.js"
},
"engines": {
"node": "16.15"
}
}
This is the config.json in db folder:
{
"development": {
"username": "postgres",
"password": "10300",
"database": "weblogin",
"host": "127.0.0.1",
"dialect": "postgres",
"logging": false
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"use_env_variable": "DATABASE_URL"
}
}
Also added this segment in models/index.js
...
sequelize = new Sequelize(process.env[config.use_env_variable], {
dialect: "postgres",
dialectOptions: {
ssl: true,
},
});
} else {
...
UPDATE
when I run the vscode debugger it shows same error preventing it to send any variables.
debugger
I don't know from where the error is coming from.
This is app.js
const express = require("express");
const app = express();
const db = require("./db/models");
const cors = require("cors");
const passport = require("passport");
const { localStrategy, jwtStrategy } = require("./middleware/passport");
const userRoutes = require("./routes/users");
require("dotenv").config();
//middleware
app.use(express.json());
app.use(cors());
//passport
app.use(passport.initialize());
passport.use(localStrategy);
passport.use(jwtStrategy);
//routes
app.use(userRoutes);
//Not Found
app.use((req, res, next) => {
next({
status: 404,
message: "Path not found",
});
});
//Error Handling
app.use((error, req, res, next) => {
res
.status(error.status || 500)
.json({ message: error.message || "Internal Server Error" });
});
db.sequelize.sync({ alter: true });
//db.sequelize.sync({ force: true });
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log("application is running" + PORT);
});
Can you help me figure how to solve this issue?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阅读追溯是您必须学会做的XSS脖子的痛苦。当您这样做时,您会看到包含
新semelize
的行最终导致您的崩溃的其他功能。 使用文件和行号来确定您的哪一行负责。崩溃本身是由于崩溃代码期望某些变量nationurl
是一根绳子,但发现它是不确定的。一旦确定了最终导致崩溃的您的代码中的行,您就可以检查该行。我相信这是一个。
通常,该续集构造函数的第一个参数是DBMS服务器的URL。但是您的程序抱怨无效URL。
因此,您可能希望将您的代码更改为:
我怀疑您会发现这三行中的第一行分配了nemelizeurl的无效值。您当然会发现您对续集构造函数的调用中有问题。
错误地处理配置和环境变量很容易错误地处理。当您在Heroku上部署时,您必须正确处理它们或繁荣!
Reading tracebacks is a pain in xss neck that you must learn to do. When you do, you'll see that your line containing
new Sequelize
called other functions that eventually caused your crash. Use file and line numbers to figure out which of your lines of code is responsible. The crash itself is due to the fact that the crashing code expected some variable namedurl
to be a string, but instead found that it was undefined.Once you've identified the line in your code that eventually led to the crash, you then examine that line. It is, I believe, this one.
Ordinarily the first parameter to that Sequelize constructor is the URL of a dbms server. But your program is complaining of a null URL.
So, you may wish to change your code to:
I suspect you will discover the first of those three lines assigns a null value to sequelizeURL. You certainly will find that your call to the Sequelize constructor has something wrong in it.
It's easy to handle config and environment variables incorrectly. And when you deploy on Heroku, you must handle them correctly or, boom!
您能添加引发错误的实际代码吗?
更好的是调试状态,您可以在VS代码中附加扣除式扣除或仅键入
调试器;
在代码中,然后从CLI启动,然后显示代码和值。
如果我们不知道实际引起问题的是什么,我们无能为力
Could you please add the actual code which throws the error?
Even better would be the debugged state, you can either attach a debguger in VS Code or just type
debugger;
in the code and then start it from the CLI and then show the code and the values.
We can't help if we don't know what is actually causing the problem