简体   繁体   English

无法/ GET-此Express Server有什么问题?

[英]Cannot /GET - What's wrong with this Express Server?

I'm creating a basic app to learn Express, but can't seem to set it up right. 我正在创建一个基本的应用程序来学习Express,但似乎无法正确设置它。 When I run the app I get a Cannot /GET error. 当我运行应用程序时,出现Cannot /GET错误。 The basic outline is something like this: 基本轮廓如下所示:

In the top directory - 在顶层目录中-

var express = require('express');
var app = express();

var getWx = require('./incoming/getWx.js');

app.set('port', process.env.PORT || 1983);
app.use('/getWx', getWx);

app.listen(1983);

Then, in /incoming/getWx.js , I have: 然后,在/incoming/getWx.js ,我有:

var express = require('express');
var app = express();

var router = express.Router();

router.route('/')
  .get(function(request, response) {
    // do thing here 
  })


module.exports = router;

Anything stand out here as wrong? 这里有什么不对劲的地方吗? Trying to do this with a router as my app will end up with multiple files. 尝试使用router执行此操作,因为我的应用程序最终会包含多个文件。

You get that error because you probably trying to access the path / ... 您收到该错误,因为您可能试图访问路径/ ...

Which don't have any router set to handle it... 没有设置路由器的路由器...

The router you set up handles the path /getWx 您设置的路由器处理路径/getWx

If you set stomething like this: 如果您这样设置存储空间:

app.use('/', getWx); app.use('/',getWx);

The accessing path / will return something... 正在访问的路径/将返回某些内容...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM