node.js - 如何从feathers.js 服务重定向

标签 node.js feathersjs

我有一个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/

相关文章:

javascript - 从 Node.js 中的 Json 对象下载文件

node.js - gke - redis - 连接超时

node.js - Sequelize 向关联添加属性

regex - 自动正则表达式学习器?

javascript - FeathersJS/Angular 4 中的身份验证

mysql - FeathersJS 似乎将查询限制为 1000,即使您将 $limit 设置为高于 1000

Node.js - process.exit() 与 childProcess.kill()

使用 Feathers-authentication-client 时出现 Aurelia 依赖问题

javascript - FeathersJS 中的非 CRUD 路由

vue.js - 从 vue 客户端使用 mongoose 进行模糊搜索