Cannot POST form node.js - express

后端 未结 3 1577
抹茶落季
抹茶落季 2020-12-05 07:26

Using express 3.1.0 I have a super simple form:

3条回答
  •  误落风尘
    2020-12-05 07:54

    router.route('/signup')
    
        // (accessed at POST http://localhost:3000/api/signup)
        .post(function(req, res) {
            var username = req.body.username;
            var password = req.body.password;
            res.json(
                { 
                   message: 'signup success',
                    username : username,
                     password : password,
                }
            );
        })
        .get(function(req,res){
            res.json({message: 'get request from signup'});
    });
    
    // REGISTER OUR ROUTES -------------------------------
    // all of our routes will be prefixed with /api
    app.use('/api', router);
    

提交回复
热议问题