找不到快速路由器发布路由

时间:2019-03-18 22:49:13

标签: node.js express post jwt http-status-code-404

因此,我一直在关注一些教程,以尝试使用JWT身份验证和Express来获得api。但是发布路线会继续返回404(找不到)。我试过添加行之有效的GET路由。 (我确实在POSTMAN中选择了正确的请求类型)有什么想法吗?

// /routes/userRoute.js
const express = require('express');
const router = express.Router();
const userController = require('../controllers/userController');

router.post('/register', userController.create);
router.post('/authenticate', userController.authenticate);

module.exports = router;

// app.js
const express = require('express'),
app = express(),
port = process.env.PORT || 4000,
mongoose = require('mongoose'),
jwt = require('jsonwebtoken'),
cors = require('cors'),
user = require('./models/userModel');

const auth = require('./auth/verifyToken'),
    bodyParser = require('body-parser');

const userRoutes = require('./routes/userRoutes');

// mongoose instance connection url connection
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/frits',{useNewUrlParser:true});

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use(cors());

app.get('/', function(req, res){
    res.json({"Welkom" : "Frits API"});
});

app.use('/user', userRoutes);

app.use(function(req, res) {
    res.status(404).send({url: req.originalUrl + ' not found'})
});

app.listen(port);

console.log('frits API server started on: ' + port);

0 个答案:

没有答案