Skip to content

Commit

Permalink
feat: Refactored design away from manipulating the prototype change o…
Browse files Browse the repository at this point in the history
…f the request/response pair

BREAKING CHANGE: This design changes the Express app from a Function to a Class which has many impacts. One example is when creating the applicatio
n. This design introduces 3 main classes, ExpressApp, ExpressResponse, and ExpressRequest. The req/res pair are now instances of ExpressRequest/Response, which extend the http.IncomingMessage/ServerResponse. I tried several approaches to removing the prototype chain design, this one was the only one where I was able to successfully change the design and tests still pass (except for the ones that tested the prototypical features).

```javascript
const app = express()
const server = app.listen()
```

Some things you used to be able do that you can no longer do are:

```javascript
express.response.foo = function() { this.send('bar') }
```
Checkout the Exports.mjs test to see how to accomplish the same thing with the new design.
  • Loading branch information
joeyguerra committed Jan 6, 2024
1 parent 49f14e2 commit 702007c
Show file tree
Hide file tree
Showing 19 changed files with 2,401 additions and 2,144 deletions.
4 changes: 2 additions & 2 deletions examples/vhost/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ redirect.use(function(req, res){

var app = module.exports = express();

app.use(vhost('*.example.com', redirect)); // Serves all subdomains via Redirect app
app.use(vhost('example.com', main)); // Serves top level domain via Main server app
app.use(vhost('*.example.com', redirect.handle.bind(redirect))); // Serves all subdomains via Redirect app
app.use(vhost('example.com', main.handle.bind(main))); // Serves top level domain via Main server app

/* istanbul ignore next */
if (!require.main) {
Expand Down
Loading

0 comments on commit 702007c

Please sign in to comment.