Thursday, 25 May 2017

Sails and Node not creating individual pages

Just learning sails with node and have been running into an issue, I have all of my views created and my user controller, but when I click sign up, it takes me to localhost/signup and 404s me. Alternatively, going to /user, /login, /quiz all end in 404s as well.

This is my views folder contents:

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

My signup method should be routing me to quiz.ejs, but just kind of breaks. These are my custom routes:

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

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

These routes are referencing my UserController.js which have a login, logout and signup function, here are those functions, here is my sign up function:

    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');
        });
    }

As you can see, my return is set to /quiz, but it doesn't seem to fire. Edit: on click, I am receiving this console error as well:

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

What could be causing this?



via ether

No comments:

Post a Comment