简体   繁体   中英

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. When I run the app I get a Cannot /GET error. 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:

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.

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

If you set stomething like this:

app.use('/', getWx);

The accessing path / will return something...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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