Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 703 Bytes

File metadata and controls

29 lines (22 loc) · 703 Bytes
title Middleware

Middlewares may be included by passing file you specify in your start config.

import { defineConfig } from "@solidjs/start/config";

export default defineConfig({
  middleware: "./src/middleware.ts"
});

Inside the middleware file, you can export a createMiddleware function.

import { createMiddleware } from "@solidjs/start/middleware";

export default createMiddleware({
  onRequest: [
    event => {
      console.log("GLOBAL", event.request.url);
    }
  ]
});

Middleware supports 2 lifecycles: onRequest and onBeforeResponse. If you return a value from middleware it will respond with that, otherwise it will run the next one in the chain.