NodeJS 想要在节点js中将本地主机http转换为https .........出现某种错误[已关闭]

cdmah0mi  于 2023-01-12  发布在  Node.js
关注(0)|答案(1)|浏览(115)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
2天前关闭。
Improve this question
所以这是我的代码,我不知道如何使用它与此。虽然它的工作与简单

https.createserver(options)

但是我希望它能在整个localhost项目上运行,也就是“app”。我试着用这个来运行它

const server = https.createServer(app[options]);
server.listen(process.env.PORT, (req, res) => {
  console.log("hii")
})

但出现此错误:[下面是错误,我也来显示代码][1] [1]:https://i.stack.imgur.com/jNVph.png

const https = require("https");

const fs=require('fs')
const path = require("path");
var cons = require("consolidate");
var express = require("express");
var app = express();
const options ={
  key:fs.readFileSync('certificates/key.pem'),
  cert:fs.readFileSync('certificates/cert.pem') 
}

const server = https.createServer(app[options]);
const dotenv = require("dotenv");
dotenv.config();
const signuprouter = require("./Controllers/signUpController");
const loginrouter = require("./Controllers/loginController");
const dashbaordrouter = require("./Controllers/dashboardController");
const hotelrouter=require("./Controllers/hotelsController")
const userDashboard=require("./Controllers/userDashboard")
const cors = require("cors");
const swig = require("swig");
app.use(express.json())

app.engine("html", cons.swig);
app.set("views", path.join(__dirname, "pages/front-end"));
app.set("view engine", "html");
app.use(express.static(path.join(__dirname, "/public")));
app.use("/", signuprouter);
app.use("/", loginrouter);
app.use("/", dashbaordrouter);
app.use("/", hotelrouter);
app.use("/", userDashboard);

server.listen(process.env.PORT, (req, res) => {
  console.log("hii")
})
module.exports=server;
wvt8vs2t

wvt8vs2t1#

createServer接受一个指定凭证的 *options对象 * 和一个可以是express应用程序的 * 中间件函数 *。

const server = https.createServer(options, app);
server.listen(process.env.PORT, (req, res) => {
  console.log("hii")
})

相关问题