我有一个大型快递应用程序,我已经移动到节点7并使用Angular 2转换前端。
所有似乎都在工作,除了...... router.post(...)调用 所有router.get(...)路由都能正常工作。但是router.post(...)路由都响应404的。
路由的示例如下:
<routes.js>
'use strict';
import errors from './components/errors';
import path from 'path';
export default function(app) {
// Insert routes below
app.use('/api/logins', require('./api/login'));
app.use('/api/users', require('./api/user'));
app.use('/api/version', require('./api/version'));
...
app.use('/auth', require('./auth'));
// All undefined asset or api routes should return a 404
app.route('/:url(api|auth|components|app|bower_components|assets)/*')
.get(errors[404]);
// All other routes should redirect to the index.html
app.route('/*')
.get((req, res) => {
res.sendFile(path.resolve(app.get('appPath') + '/index.html'));
});
}
,例如
'use strict';
let express = require('express');
let router = express.Router();
let controller = require('./user.controller');
let auth = require('../../auth/auth.service');
router.post('/', auth.hasRole('admin'), controller.create);
router.get('/', auth.hasRole('admin'), controller.index);
router.get('/clean', auth.hasRole('admin'), controller.cleanDatabase);
router.get('/user/:sharingFromUserId', auth.isAuthenticated(), controller.getUserSharingFromUser);
....
然而,当我发帖时,我看到了:
POST http://localhost:9000/users/ 404 (Not Found)
Intellij中有一个奇怪的提示,表明route.post()不是正确的函数????在编辑器中,IDE似乎暗示这是AuthHttp.post()函数,它正在前端的webpack部分中使用。怎么会这样???