【问题标题】:Server is loading forever as I use the following code for server.js服务器正在永远加载,因为我对 server.js 使用以下代码
【发布时间】:2021-12-24 18:16:06
【问题描述】:

我在 server.js 文件中使用了此代码,并在名为 website 的文件夹中使用了 app.js 中的主要代码。当我在终端中使用 node server.js 运行 localhost 并在浏览器中运行 http://localhost:3000 时,它会永远加载而不会停止。

const bodyParser=require('body-parser');
const express=require('express');
const app=express();
/*dependencies*/
//Here we are configuring express to use body-parser as middle-ware.
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//cors for cross origin allowance
const cors=require('cors');
app.use(cors);
//making a local server
const port= 3000;
const server = app.listen(port, ()=>{console.log(`running on localhost: ${port}`)});
app.use(express.static('website'));

【问题讨论】:

  • app.use() 中使用cors() 而不是cors,例如app.use(cors());

标签: javascript node.js server localhost


【解决方案1】:

移除 CORS 模块。您可能不需要它,它是无限加载的原因。如果需要,您可能应该搜索其他模块。

【讨论】:

    猜你喜欢
    • 2020-07-31
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-11
    相关资源
    最近更新 更多