【发布时间】:2020-08-05 02:53:52
【问题描述】:
我在这里遇到了一个小问题。如果我输入了错误的路线,我想显示404 not found。
如果我转到http://localhost:3000,下面的代码只会显示404 not found/
但是当我输入http://localhost:3000/wrongroute 时,它会显示Cannot GET /wrongroute 而不是
404 not found.
const bodyParser = require("body-parser");
const mysql = require('mysql');
const router = express.Router();
const db = mysql.createConnection({
host: 'xxx.xx.xx.xx',
user: 'root',
password: '12345',
database: 'test'
});
db.connect((err) =>{
if(err){
throw err;
}
console.log('Mysql Connected');
// res.send("Mysql Connected");
});
router.post('/login', function (req, res) {
res.send("This is from login route");
res.end();
})
router.post('/signup', function (req, res) {
res.send("This is from signup route");
res.end();
})
router.get('/', function(req, res){
res.send("404 not found");
});
module.exports = router;
【问题讨论】:
标签: javascript node.js