現在通過webStorm生成express項目,express版本是4.2.0,其中的路由使用類似如下的方式控制.
求解如何修改能達到login處理post請求。
var express = require('express');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
var login = require('./routes/login');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/users', users);
app.use('/login', login);
想讓我的login路由來處理post請求
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res) {
var username = req.param('username', null);
var password = req.param('password', null);
console.log("username:" + username + " password:" + password);
res.send('login');
});
求解如何修改能達到login處理post請求。
已經解決。。。查看express文檔api
router.post('/',function(){
});