godaddy / godaddy/slay

`req.app` is not a reference to the `slay.App`

Open
#15 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
51
Forks
12
PR merge metrics
No merged PRs in 30d

Description

### Problem
I am trying to access `app.config` that is exposed by slay inside of a middleware, but it doesn't exist. Express [exposes](https://expressjs.com/en/api.html#req.app) both `req.app` and `res.app` for this purpose.

#### Example:
```js
// foo-middleware.js
module.exports = foo(req, res, next) {
// req.app exists
// req.app.config does not exist
next();
}
```

### Investigation

This reference is not updated in slay, and does not have a reference to the new app properties that are [documented](https://github.com/godaddy/slay#app).

`req.app` and `res.app` seem to be set on the prototype of express's app as a [re-writable property](https://github.com/expressjs/express/blob/b8e50568af9c73ef1ade434e92c60d389868361d/lib/express.js#L45-L54
). Happy to open up a PR to change this in slay, unless there is another way to access the slay app instance from inside of a middleware. (to get access to app.config, for example). This should work by setting `app.request.app = app` (the slay app instead of the express app).

It looks like `slay` and `broadway` inherit properties from express, but don't update this `app.request.app` reference.

Contributor guide

Open the contributing guide

Research direction

Start at slay's app.request.app setup and compare it with the reference behavior in Express's lib/express.js. Verify the middleware example and confirm that req.app and res.app expose the slay app properties, including app.config, when the change is complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.