| Name | Modified | Size | Downloads / Week |
|---|---|---|---|
| Parent folder | |||
| README.md | 2018-09-18 | 3.4 kB | |
| v0.5.0 source code.tar.gz | 2018-09-18 | 236.7 kB | |
| v0.5.0 source code.zip | 2018-09-18 | 278.1 kB | |
| Totals: 3 Items | 518.2 kB | 0 | |
Breaking
-
Remove Promise around
app.listen(#19): dc56b9d, e34a2a4The previous
polka.listenwas a Promise & had structured input, both of which made it unique from existing frameworks. However, it was also a gotcha for projects migrating from existing frameworks.Instead,
polka.listennow passes all arguments directly to the underlingserver.listen, which is arguably more "in tune" with the rest of Polka's ideology around nativehttpintegration.The new method will now rerun the current
Polkainstance directly, allowing you to continue chaining from it, or allowing you to grab theserverorhandlervalues immediately. Previously,.listen()always had to be last in your chain & resolved to nothing.
```js // Could not do this before 0.5.0 const { server, handler } = polka().listen();
// Or this! const app = polka().listen(PORT, onAppStart);
app.use('users', require('./users')) .get('/', (req, res) => { res.end('Pretty cool!'); }); ```
-
Removed built-in
.METHOD()prototype methods for all 34http.METHODS: 6d5d094The large majority of these are never used; eg:
ACL,MKCOL,MKCALENDAR, etc.These HTTP/1.1 verbs are supported / available to your Polka applications:
- GET ->
.get() - POST ->
.post() - OPTIONS ->
.options() - DELETE ->
.delete() - PATCH ->
.patch() - PUT ->
.put() - HEAD ->
.head() - CONNECT ->
.connect() - TRACE ->
.trace()
- GET ->
Features
-
Polka now supports multiple route-specific handlers! (#18): 42574ac, aac1859, a82f571
This was the most anticipated & most request feature for Polka 🎉
Put simply, variadic route handlers allows you to chain middleware for specific paths. This was only feasible before through
req.pathfilters on sub-application or global middleware. Routes can now be modular, allowing you to compose/reuse your server route-by-route instead of group-by-group.Supporting this dramatically improves compatibility between Express and Polka applications. Most importantly, though, this did not come at the expense of performance~!
Here's a very basic example using
passport, which was often a driver for this feature request:
```js const app = polka();
app.post('/login', // This "guards" this route, executing first passport.authenticate('local', { failureRedirect: '/login' }), // This is the "main" function of this route function (req, res) { res.redirect('/'); }); ```
- NEW
@polka/urlpackage: 44a5757, da00320, 87bac82, 17c54a7 Super lightweight URL parser built specifically for Node.js servers.
Patches
- (
send-type) Lowercase all customheaderskeys before parsing (#57): 83731c5
Examples
- Added
examples/with-apollo(#48): a7a38c4 - Added
examples/with-nextjs(#48): a7a38c4 Thanks @jerolan! - Update
examples/with-socketio: a9f0f58
Chores
- Fix README:
req.pathinstead ofreq.pathname(#62): a4d96b9 Thanks @antoineneff! - Add Middleware Sequence documentation: d6296ed
- Update Express comparisons: d6296ed, 99f4fe9
- Misc README changes: 734ee31, 35fb3d8, e43bf6f