polka

A micro web server so fast, it'll make you dance!

MIT License

Downloads
33.9M
Stars
5.3K
Committers
14

Bot releases are hidden (Show)

polka - v1.0.0-next.25 Latest Release

Published by lukeed 7 months ago

NEW

  • Add @polka/compression package! (#148): a2105e0, 7745eb4
    A lightweight compression replacement, with opt-in Brotli support.
    Thank you @developit! 🙌

Chores

  • Add a licenses.dev badge to README files: 5ff616a
    This service recursively analyzes entire dependency graphs to ensure that a package (or your project) is using permissive licenses. For example, here's a results table for polka@next and a larger astro example.

Full Changelog: https://github.com/lukeed/polka/compare/v1.0.0-next.24...v1.0.0-next.25

polka - v1.0.0-next.24

Published by lukeed 11 months ago

Features

  • Support TypeScript node16/nodenext/bundler module resolutions support (#192, #200):
    Thank you @didinele and @benmccann~!

Patches

  • (polka) Upgrade to [email protected] which improved optional wildcard pattern support: 862b08e
    See [email protected] release notes for more information.

  • (@polka/send) Apply custom response headers for piped stream (#198): 1568db3
    Thank you @aral


Full Changelog: https://github.com/lukeed/polka/compare/v1.0.0-next.22...v1.0.0-next.24

polka -

Published by lukeed about 3 years ago

Patches

  • (polka) Ensure error.status is numeric before assigning as status code (#178): 8448ac0
    Thank you @lovasoa

  • (polka) Ensure error.status is 3-digit status code: 561558b

polka -

Published by lukeed about 3 years ago

Breaking

  • (polka) Remove code property support for next() errors: f95a5b4
    Previously any errors or custom error-objects could use the code property to set the response status code. However, this could pose a problem with native Error types that set an error code (eg, "ENOENT") which is an invalid status code.
    Now you must use the status property, which was always supported, but took a backseat to code's existence. Express also supports the status property.
    next({
    -- code: 422,
    ++ status: 422,
       message: 'Invalid content',
    });
    

Chores

  • (@polka/url) Accomodate an updated error message in test expectant: d30d448
polka -

Published by lukeed about 3 years ago

Breaking

  • (@polka/url): Remove toDecode parameter (#175): e45fe88
    Apparently no one was using it except for me 😆 so I removed it as it was causing cache/mutation conflicts in rare cases downstream.
polka -

Published by lukeed about 3 years ago

Patches

  • (@polka/url): Ensure toDecode value is considered during req._parsedUrl cache match: f64b4bb
    For example, if you parse a URL without decoding it, that previous result should not be reused if you call parse again w/ toDecode set to true this time. Should be true for the reverse situation too.
polka -

Published by lukeed about 3 years ago

Breaking

  • No longer automatically decodes req.url and req.path values anymore (#172): 6ef32a6, 363e1f6
    Previously, these properties had already passed through decodeURIComponent, which could affect Polka's own routing (#142) or external middleware that always expected req.path and/or req.url to remain percent-encoded.

    However, all req.params values are still decoded!

    This change aligns Polka with the default Express decoding behavior.

Chores

  • (url): Mention toDecode parameter in @polka/url README (#168): 363e1f6
polka -

Published by lukeed about 6 years ago

Breaking

  • Remove Promise around app.listen (#19): dc56b9d, e34a2a4

    The 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 underling server.listen, which is arguably more "in tune" with the rest of Polka's ideology around native http integration.

    The new method will now rerun the current Polka instance directly, allowing you to continue chaining from it, or allowing you to grab the server or handler 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 34 http.METHODS: 6d5d094

    The 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()

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

  • (send-type) Lowercase all custom headers keys 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.path instead of req.pathname (#62): a4d96b9
    Thanks @antoineneff!
  • Add Middleware Sequence documentation: d6296ed
  • Update Express comparisons: d6296ed, 99f4fe9
  • Misc README changes: 734ee31, 35fb3d8, e43bf6f
polka -

Published by lukeed over 6 years ago

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 up http servers. This meant that all servers were just utilizing memory & never served a purpose, since only the main application's server 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 to req.path (#29): 7d467f3
    This is for Express compatibility. A lot of popular apps/middlewares rely on req.path (like webpack-dev-server) & it doesn't make to maintain req.pathname and req.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

  • Added examples/with-nuxtjs: ff27865
  • Added examples/with-graphql: b929ada
  • Added examples/with-sirv: 1284606
polka -

Published by lukeed over 6 years ago

Patches

  • FIX: Ensure req.query is always an object (#28): 73392ea

    Thanks @josiahwiebe!

  • FIX: Ensure req.originalUrl always exists: bb9e366, dacb2e2

  • Update README benchmarks after polka.handler changes: 606b0cd

polka -

Published by lukeed over 6 years ago

Patches

  • FIX: Prevent root-level wildcard routes from stealing middleware requests (#26): dfac4b4

  • Add tests to track middleware-vs-wildcard handling: f4c83d8

  • Update README benchmarks after polka.handler changes: f1a1372

Examples

  • Added examples/with-afterjs: 025614f
polka -

Published by lukeed over 6 years ago

Patches

  • FIX: Defer request property mutations until a sub-group is actually called: 3120116, df98c4c

    Previously, 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

  • Added examples/with-morgan: e8240a6

    Illustrates the fix in 3120116, preventing regressions.

polka -

Published by lukeed over 6 years ago

Patches

  • FIX: Only mutate req.url and req.pathname if sub-group is known: f4e62bf

    This is an important fix! Any cases of serve-static that were mounted without a basename path were behaving unexpectedly. This is because req.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's index.html content was always sent.

  • Ensure that sub-groups & basenames always include a leading slash: 531c92d

    This makes it easier & quicker to mutate the req.url and req.pathname values once a sub-group is found.

  • Update README benchmarks after polka.handler changes: d8016cc

Examples

  • Added examples/with-socketio: 2d15837
  • Added examples/with-firebase-admin: 4c09fbf, b52f103, 5a11a4f
  • Updates all examples with serve-static usage: 1cfbb25
polka -

Published by lukeed over 6 years ago

Features

  • Add onError and onNoMatch 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: 11052b7

    Use @polka/send or @polka/send-type instead.

  • Remove app.start prototype: a24fae2

    Use app.listen instead.

  • Require a base path to mount sub-applications: e3c6966

    • Mutates the req.url once a base app or middleware group has been found
      _ Includes a req.originalUrl value once a base has been matched

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 the app.handler gives it a chance to, rather than exiting immediately.

  • Respond with 404 instead of 405 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

Misc

  • Add lots of tests~!: 4a6b870, 17f1c85, 7054f8f, 22ed1eb, 1b45661
  • Convert to monorepo: 7e583fc, a9d5382
  • Move all tests into root: 7a8f338
  • Update documentations: 4611577, 2e4167c
  • Update benchmarks: 6c4dd86
polka -

Published by lukeed over 6 years ago

Patches

  • Exits the app handler early if no middleware to loop thru: ded9d0b

    Quick little performance win; avoids unnecessary executions.

polka -

Published by lukeed almost 7 years ago

Patches

  • Ensure asynchronous middleware functions are awaited: bf626a3, b53874a

    The previous while loop only waited for synchronous res.end or next() calls. If any Promise or Stream based middleware worked, it was purely by luck 😅

  • Update benchmark code & result sets: f8a65b8, f5b3701, 76a0a37

polka -

Published by lukeed almost 7 years ago

Patches

  • Ensure req.params is populated with pathname segments only (#6): d64ae9e
polka -

Published by lukeed almost 7 years ago

Minor Changes

  • Add support for sub-applications 🎉 (#1): 17f1e85

    This was a core chunk for releasing 1.0. Still not quite ready as there are a few other API decisions to be made, but this takes us most of the way there.

  • Reverted app.handler's signautre to (req, res, parsed): ddbf15c, d72cd14

    Exposing a next callback was completely useless as it would never be called, unless by accident — even though, it shouldn't have been allowed. 😆

    Instead, an optional parsed parameter allows the developer to parse the URL on their own terms, do whatever they want with the info, and then pass down the same information to the (nested?) app handler. Although parseurl is super fast, the fastest function is the one you never call~ 😉

Examples

  • Added examples/sub-app: 6b2ad16
  • Added examples/async-fetch: 7ce5cdc

Patches

  • Removed unused import & renamed parseurl import: 0f559b6
  • Added sub-application tests: b07d146