config/routes.js 中定义的路由出现 404(未找到)错误

Getting 404 (not found) error for routes defined in config/routes.js

刚刚学习使用 node 航行并且遇到了 运行 问题,我已经创建了所有视图和我的用户控制器,但是当我单击注册时,它会将我带到 localhost/signup和 404s 我。或者,转到 /user/login/quiz 也都以 404 结尾。

这是我的视图文件夹内容:

- 403.ejs
- 404.ejs
- 500.ejs
- homepage.ejs
- index.ejs
- layout.ejs
- quiz.ejs

我的注册方法应该将我路由到 quiz.ejs,但只是有点中断。这些是我的自定义路线:

module.exports.routes = {
    // HTML Views
    '/': { view: 'index' },
    '/quiz': { view: 'quiz' },

    // Endpoints
    'post /login': 'UserController.login',
    'post /signup': 'UserController.signup',
    '/logout': 'UserController.logout',
};

这些路由引用了我的 UserController.js,它有一个 loginlogoutsignup 函数,这是那些函数,这是我的 sign up功能:

    signup: function (req, res) {

        // Attempt to signup a user using the provided parameters
        User.signup({
            name: req.param('name'),
            email: req.param('email'),
            password: req.param('password'),
            avatar: req.param('avatar'),
        }, function (err, user) {
            // res.negotiate() will determine if this is a validation error
            // or some kind of unexpected server error, then call `res.badRequest()`
            // or `res.serverError()` accordingly.
            if (err) return res.negotiate(err);

            // Go ahead and log this user in as well.
            // We do this by "remembering" the user in the session.
            // Subsequent requests from this user agent will have `req.session.me` set.
            req.session.me = user.id;
            req.session.name = user.name;


            // If this is not an HTML-wanting browser, e.g. AJAX/sockets/cURL/etc.,
            // send a 200 response letting the user agent know the signup was successful.
            if (req.wantsJSON) {
                return res.ok('Signup successful!');
            }

            // Otherwise if this is an HTML-wanting browser, redirect to /welcome.
            return res.redirect('/quiz');
        });
    }

如您所见,我的return设置为/quiz,但是好像没有触发。编辑:单击时,我也收到此控制台错误:

POST http://localhost:1337/signup 404 (Not Found)

可能是什么原因造成的?

经过一些摆弄和查看我的文件后,我意识到 Sublime 没有保存我对文件名的更改。当它实际上被命名为 usercontroller.js 时,我试图引用 UserController.js,更改它让一切再次顺利运行!