Releases: lukeed/polka
v0.5.0
Breaking
-
Remove Promise around
app.listen
(#19): dc56b9d, e34a2a4The previous
polka.listen
was 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.listen
now passes all arguments directly to the underlingserver.listen
, which is arguably more "in tune" with the rest of Polka's ideology around nativehttp
integration.The new method will now rerun the current
Polka
instance directly, allowing you to continue chaining from it, or allowing you to grab theserver
orhandler
values immediately. Previously,.listen()
always had to be last in your chain & resolved to nothing.// 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.path
filters 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: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/url
package: 44a5757, da00320, 87bac82, 17c54a7
Super lightweight URL parser built specifically for Node.js servers.
Patches
Examples
- Added
examples/with-apollo
(#48): a7a38c4 - Added
examples/with-nextjs
(#48): a7a38c4
Thanks @jerolan! - Update
examples/with-socketio
: a9f0f58
Chores
- Fix README:
req.path
instead ofreq.pathname
(#62): a4d96b9
Thanks @antoineneff! - Add Middleware Sequence documentation: d6296ed
- Update Express comparisons: d6296ed, 99f4fe9
- Misc README changes: 734ee31, 35fb3d8, e43bf6f
v0.4.0
Minor Changes
-
Add new
opts.server
option: 276056c, e93ae66, d2f5f96
This allows Polka to attach to predefined, existing servers. It's an alternative approach to booting Polka and wrapping it with another parent server. -
Initialize
server
only when needed: 276056c
Without this, all sub-applications were preemptively booting uphttp
servers. This meant that all servers were just utilizing memory & never served a purpose, since only the main application'sserver
mattered.This change means that the following code sample no longer works:
let { server } = polka(); //=> before: "server" was http.Server //=> current: "server" is undefined
-
Rename
req.pathname
toreq.path
(#29): 7d467f3
This is for Express compatibility. A lot of popular apps/middlewares rely onreq.path
(likewebpack-dev-server
) & it doesn't make to maintainreq.pathname
andreq.path
values.
Patches
- Push root-based middleware group into global middleware: 46285f9
This is mostly a Express-compatibility thing; funky but a needed workaround for some.
Chores
- Fix readme docs: 37fe875, 46086ae
- Rewrite tests with
async
for convenience / sanity: c17440f - Fix tests after
[email protected]
update: 8af07b5
Examples
v0.3.4
v0.3.3
v0.3.2
Patches
-
FIX: Defer
request
property mutations until a sub-group is actually called: 3120116, df98c4cPreviously, given a global logger, any
bware
-path would instantly mutate the request object. This means that the information is changed before any part of the loop begins.For example, when the global logger actually runs, the wrong URL/pathname is printed.
-
Tests: Chain
axios
deeply for easier debugging in the future: b0c9c6e -
Update README benchmarks after
polka.handler
changes: a9c8d4a
Examples
v0.3.1
Patches
-
FIX: Only mutate
req.url
andreq.pathname
if sub-group is known: f4e62bfThis is an important fix! Any cases of
serve-static
that were mounted without abasename
path were behaving unexpectedly. This is becausereq.url
was mutated as soon as a route-handler was not found, turning incoming assets like/app.js
into/
, which meant that the target directory'sindex.html
content was always sent. -
Ensure that sub-groups &
basenames
always include a leading slash: 531c92dThis makes it easier & quicker to mutate the
req.url
andreq.pathname
values once a sub-group is found. -
Update README benchmarks after
polka.handler
changes: d8016cc
Examples
v0.3.0
Features
-
Add
onError
andonNoMatch
options: e431583 -
Mount middleware groups & sub-applications to specific base pathnames (#8): e3c6966
-
Execute sub-applications' included middleware: e3c6966, b23d29f
We pass off the entire request to the sub-app directly, rather than stealing & reconstructing its routes in the main Polka instance.
-
Offer
@polka/send
and@polka/send-type
response helpers (#5): 815aaef, 2dac7a0
Breaking
-
Remove
app.send
prototype: 11052b7Use
@polka/send
or@polka/send-type
instead. -
Remove
app.start
prototype: a24fae2Use
app.listen
instead. -
Require a
base
path to mount sub-applications: e3c6966- Mutates the
req.url
once abase
app or middleware group has been found
_ Includes areq.originalUrl
value once abase
has been matched
- Mutates the
Patches
-
Allow asynchronous or dynamically-routed middleware to terminate the response: e3c6966
A middleware like
serve-static
can't know ahead of time if it will find a file. Now theapp.handler
gives it a chance to, rather than exiting immediately. -
Respond with
404
instead of405
if no route definition.
Examples
- Added
examples/with-body-parser
: 00d997f - Added
examples/with-https
: 2ecb748 - Added
examples/with-serve-static
: 7a04093, cacc5be - Added
examples/with-uws
: 9965f8a - Updated
async-json
&sub-app
demos: b338d75, 90c1fd2