Skip to content

Commit

Permalink
fix(express): Ensure Express options can be set before configuring RE…
Browse files Browse the repository at this point in the history
…ST transport (#2655)
  • Loading branch information
daffl authored Jun 6, 2022
1 parent 532eda0 commit c9b8f74
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 0 additions & 4 deletions packages/express/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ export default function feathersExpress<S = any, C = any>(
})

app.configure(routing() as any)
app.use((req, _res, next) => {
req.feathers = { ...req.feathers, provider: 'rest' }
return next()
})

return app
}
Expand Down
4 changes: 4 additions & 0 deletions packages/express/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export const rest = (options?: RestOptions | RequestHandler) => {
throw new Error('@feathersjs/express/rest needs an Express compatible app.')
}

app.use((req, _res, next) => {
req.feathers = { ...req.feathers, provider: 'rest' }
return next()
})
app.use(parseAuthentication(authenticationOptions))
app.use(servicesMiddleware())

Expand Down
6 changes: 4 additions & 2 deletions packages/express/test/rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,10 @@ describe('@feathersjs/express/rest provider', () => {

const app = expressify(feathers())
.use(function (req: Request, _res: Response, next: NextFunction) {
assert.ok(req.feathers, 'Feathers object initialized')
req.feathers.test = 'Happy'
req.feathers = {
...req.feathers,
test: 'Happy'
}
next()
})
.configure(rest(express.formatter))
Expand Down
5 changes: 4 additions & 1 deletion packages/rest-client/test/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export default (configurer?: any) => {
.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Authorization')
req.feathers.authorization = req.headers.authorization
req.feathers = {
...req.feathers,
authorization: req.headers.authorization
}
next()
})
// Parse HTTP bodies
Expand Down

0 comments on commit c9b8f74

Please # to comment.