Brisa 0.1.3

by Aral Roca

This release fixes 7 bugs. It also includes some improvements and new features, thanks to all contibutors:

Rename renderInitiator to initiator and add new features

Breaking change:

In this version, we have changed the name of renderInitiator to initiator. The reason is that it now goes beyond just rendering; it is the initiator of the request, which also tells you if it is an API route—useful in middleware.

import { Initiator } from "brisa/server";

export default function ServerComponent(props, req) {
  if (req.initiator === Initiator.INITIAL_REQUEST) {
    req.store.set("count", 0);
  }

  return <div>{req.store.get("count")}</div>;
}

Add getServer server API

In this version, we have added the getServer server API. The getServer function is used to get the server instance of Brisa. It is useful to access the server instance in the server components.

import { getServer } from "brisa/server";

// ...
const server = getServer();
/* 
{
  address: {
    address: "::",
    family: "IPv6",
    port: 63621,
  },
  development: true,
  fetch: [Function: fetch],
  hostname: "localhost",
  id: "",
  pendingRequests: 3,
  pendingWebSockets: 1,
  port: 63621,
  protocol: "http",
  publish: [Function: publish],
  ref: [Function: ref],
  reload: [Function: reload],
  requestIP: [Function: requestIP],
  stop: [Function: stop],
  subscriberCount: [Function: subscriberCount],
  timeout: [Function: timeout],
  unref: [Function: unref],
  upgrade: [Function: upgrade],
  url: URL {
    href: "http://localhost:63621/",
    origin: "http://localhost:63621",
    protocol: "http:",
    username: "",
    password: "",
    host: "localhost:63621",
    hostname: "localhost",
    port: "63621",
    pathname: "/",
    hash: "",
    search: "",
    searchParams: URLSearchParams {},
    toJSON: [Function: toJSON],
    toString: [Function: toString],
  },
  [Symbol(Symbol.dispose)]: [Function: dispose],
}
*/

Add support to rewrite routes from the middleware

In this version, we have added support to rewrite routes from the middleware. You can now modify the request.finalURL to change the route before it is processed by Brisa server. In this way, they can be processed from the Brisa RPC client, preserving the store and with a reactive update.

// src/middleware.ts
export default async function middleware(request) {
  if (request.url.pathname === "/old") {
    // Rewrite: /old -> /new
    request.finalURL = new URL("/new", request.finalURL).toString();
    // Continue processing the request
    return;
  }

  // ... Manage other routes
}

Improve Brisa middleware redirects

During the SPA and Server Actions, you can also return redirects from the middleware. We have improved the way Brisa handles these redirects, transforming hard redirects into soft redirects when they come from the SPA.

Add example with Elysia.js

In this version, we have added an example with Elysia.js. Elysia.js is a JavaScript library that allows you to manage API routes with an ergonomic and declarative API.

// src/api/[[...slugs]].ts
import { Elysia, t } from "elysia";

const app = new Elysia({ prefix: "/api" })
  .get("/hello", () => "Brisa from Elysia entrypoint")
  .post("/", ({ body }) => body, {
    body: t.Object({
      name: t.String(),
    }),
  });

export const GET = app.handle;
export const POST = app.handle;

Fix Bun 1.1.33 breaking changes

In this version, we have fixed the breaking changes in Bun 1.1.33 regarding the JSX build AST definition. Now, Brisa is compatible with the latest Bun version, also including backward compatibility with the previous versions.

What's Changed

New Contributors

Full Changelog: https://github.com/brisa-build/brisa/compare/0.1.2...0.1.3