[英]node - How to get POST request params and then redirect user in express
我在尝试为使用 express 管理请求的 nodejs cli 脚本设置 post 端点时遇到了这个问题
app.use( express.static( path.format({dir: __dirname, base: 'client/dist'})) );
app.use( express.json() );
app.get('/:uid', (req, res) => res.sendFile(path.format({dir: __dirname, base: 'client/dist/index.html'})) );
app.listen(this.port, async () => {
console.log(`Server started at: http://localhost:${this.port}`);
});
我使用的是 express 4.17.1
,所以不需要安装bodyParser
。 我将如何获取从我的 vue 前端发布的数据、处理它们然后重定向用户?
app.post('/action', (req, res) => {
// how I can get the passed params here and redirect user?
});
从你所拥有的非常简单:
app.post('/action', (req, res) => {
// how I can get the passed params here and redirect user?
console.log(req.body)// give you the passed parameter in post request thanks to app.use( express.json() );
res.redirect('http://google.com');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.