Skip to content

Releases: sstur/nbit

v0.13.2

24 Aug 19:49
Compare
Choose a tag to compare

In this release:

  • Fix maxAge=0 (issue #12)

v0.13.1

24 Aug 16:48
Compare
Choose a tag to compare

In this release:

  • [express] Fix: Correctly invoke next() when no route matches
  • Better error handling: pipeStreamAsync catch error from beforeFirstWrite
  • More comprehensive tests

v0.12.1

19 Aug 23:22
Compare
Choose a tag to compare

In this release:

  • Fix mimeType (issue #11)

v0.12.0

14 Aug 23:34
Compare
Choose a tag to compare

In this release:

  • Mostly refactoring and better tests
  • Explicitly support Node v14.18+, v16.10+ and v18+
  • Non-breaking change to support new HttpError(status, message)

v0.11.0

11 Aug 01:36
Compare
Choose a tag to compare

In this release:

  • Implement applicationOptions.serveFile
  • Some updates to /examples
  • Add PLATFORM constant
  • Migrate tests to vitest (except for bun which uses bun test)

It's now possible to provide a mock serveFile when writing tests.

This also allows us to support Response.file() in Cloudflare workers by providing a custom serveFile that will fetch the file from some remote source.

Example:

const { defineRoutes, createRequestHandler } = createApplication({
  root: '/home/myapp', // Optional; defaults to process.cwd()
  allowStaticFrom: ['public'],
  serveFile: async ({ fullFilePath }) => {
    if (fullFilePath === '/home/myapp/public/file.txt') {
      const mockFileContent = 'Some mock content';
      return new Response(mockFileContent, {
        headers: { 'content-type': 'text/plain' },
      });
    }
    return new Response('Invalid file path', { status: 404 });
  },
});

const routes = defineRoutes((app) => [
  app.get('/file', async (request) => {
    return Response.file('public/file.txt');
  }),
]);

const requestHandler = createRequestHandler(routes);
const request = new Request('http://localhost/file');
const response = await requestHandler(request);

expect(response.status).toBe(200);
expect(response.headers.get('content-type')).toBe('text/plain');
const body = await response.text();
expect(body).toBe('Some mock content');

Some additional details here.

v0.10.0

07 Aug 16:28
Compare
Choose a tag to compare

In this release:

  • Add support for HEAD, OPTIONS and non-standard request methods, with TypeScript auto-complete suggestions
  • Normalize methods to uppercase (at both the type level and runtime)
  • More comprehensive tests

The following is now possible:

const routes = defineRoutes((app) => [
  // Standard methods should auto-suggest in your editor using TypeScript
  app.route('HEAD', '/foo', (request) => {
    return new Response(...);
  }),
  // Non-standard methods are also allowed
  app.route('MKCOL', '/webdav', (request) => {
    return new Response(...);
  }),
]);

v0.9.0

03 Aug 03:34
Compare
Choose a tag to compare

In this release:

  • Add support for app.route(method, path, handler)
  • bun: export Request (for consistency; even though it's already a global)
  • bun: update tests
  • bun: update dependency bun-types
  • bun: Always use ESM exports (fixes examples/bun-app)
  • express: update script in package.json (fixes yarn clean)

Notes

As of this release, we now support a middleware-like wildcard route handler, which also enables custom 404 fallback. See example below.

import { attachRoutes, defineRoutes } from './application';
import * as handlers from './handlers';

const port = 3000;

const middleware = defineRoutes((app) => [
  app.route('*', '/*', (request) => {
    const authHeader = request.headers.get('authorization');
    if (authHeader !== '123') {
      throw new Error('Invalid auth');
    }
  }),
]);

const fallback = defineRoutes((app) => [
  app.route('*', '/*', (request) => {
    const message = `No resource found at path "${request.path}"`;
    return new Response(message, { status: 404 });
  }),
]);

Bun.serve({
  port,
  fetch: attachRoutes(middleware, ...Object.values(handlers), fallback),
});

v0.8.0

03 Aug 03:31
Compare
Choose a tag to compare
v0.8.0