任何人都可以帮我弄清楚为什么我的快递路线不起作用。我已经被困了几天试图解决这个问题,但是当我到达customer.js的任何路线时,我一直遇到404错误
< --------------------主服务器-------------->
var express = require("express");
var path = require('path');
var app = express();
var indexRouter = require('./routes/index');
var ordersRouter = require('./routes/orders');
var customersRouter = require('./routes/customers');
var productsRouter = require('./routes/products');
app.use('/', indexRouter);
app.use('/customers', customersRouter);
app.use('/orders', ordersRouter);
app.use('/products', productsRouter);
app.listen(80);
module.exports = app;
var express = require('express');
var router = express.Router();
router.get('/customers', function(req, res, next) {
console.log(req.status())
res.send('<p>some html</p>');
});
router.post('/customers/update/shipping', function(req, res) {
res.send('<p>someg html</p>');
});
router.post('/customers/update/billing', function(req, res) {
res.send('<p>somew html</p>');
});
router.post('/customers/update/cart', function(req, res) {
res.send('<p>some dhtml</p>');
});
module.exports = router;
&LT; --------------------------------------------- ---------&GT;
答案 0 :(得分:1)
在您的客户文件中,您的路线已经相对于/customers
。从您的所有路线中删除前导/customers
。例如:
router.get('/customers', function(req, res, next) {
console.log(req.status())
res.send('<p>some html</p>');
});
应该只是
router.get('/', function(req, res, next) {
console.log(req.status())
res.send('<p>some html</p>');
});
同样的原则适用于其他文件。