我有一个feathers.js 服务,我需要在使用post 时重定向到特定页面
class Payment {
// ..
create(data, params) {
// do some logic
// redirect to an other page with 301|302
return res.redirect('http://some-page.com');
}
}
Is there a posibility to redirect from a feathers.js service ?
最佳答案
找到了一种更友好的方式来做到这一点:
假设我们有一个自定义服务:
app.use('api/v1/messages', {
async create(data, params) {
// do your logic
return // promise
}
}, redirect);
function redirect(req, res, next) {
return res.redirect(301, 'http://some-page.com');
}
背后的想法是
feathers.js
使用 express 中间件,逻辑如下。如果链式中间件是
Object
,然后将其解析为服务,之后您可以链接任意数量的中间件。app.use('api/v1/messages', middleware1, feathersService, middleware2)
关于node.js - 如何从feathers.js 服务重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49194428/