首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >快速路由在浏览器中无限旋转

快速路由在浏览器中无限旋转
EN

Stack Overflow用户
提问于 2018-06-04 04:51:32
回答 1查看 124关注 0票数 0

在创建一个简单的服务器并尝试测试来自虚拟路由的响应时,当我在chrome中运行它时,浏览器会无限旋转,并且不会加载页面。

index.js

代码语言:javascript
复制
const express = require('express');
const bodyParse = require('body-parser');
const cors = require('cors');
const morgan = require('morgan');

const index = express();

// log formatter
index.use(morgan('combine'));
index.use(bodyParse.json);
index.use(cors());

index.get('/status', (req, res) => {
    res.send({
        message: 'herrrooo'
    })
});

index.listen(process.env.PORT || 5000);

package.json

代码语言:javascript
复制
{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "nodemon index.js",
    "dev": "concurrently \"npm run start\" "
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.18.3",
    "cors": "^2.8.4",
    "express": "^4.16.3",
    "morgan": "^1.9.0",
    "nodemon": "^1.17.5"
  },
  "devDependencies": {
    "@types/express": "^4.11.1",
    "concurrently": "^3.5.1",
    "eslint": "^4.19.1",
    "eslint-config-standard": "^11.0.0",
    "eslint-plugin-import": "^2.12.0",
    "eslint-plugin-node": "^6.0.1",
    "eslint-plugin-promise": "^3.8.0",
    "eslint-plugin-standard": "^3.1.0"
  }
}

我做错了什么??

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-04 04:56:15

更改此设置:

代码语言:javascript
复制
index.use(bodyParse.json);

要这样做:

代码语言:javascript
复制
index.use(bodyParse.json());

您没有传递正确的中间件函数,所以express在到达该中间件时被卡住了,因为中间件从未调用next()来继续下一步的请求处理。

示例here in the doc

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50670862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档