Middleware
Middlewares may be included by passing file you specify in your start config.
js
import { defineConfig } from "@solidjs/start/config";export default defineConfig({middleware: "./src/middleware.ts"});
js
import { defineConfig } from "@solidjs/start/config";export default defineConfig({middleware: "./src/middleware.ts"});
Inside the middleware file, you can export a createMiddleware
function.
tsx
import { createMiddleware } from "@solidjs/start/middleware";export default createMiddleware({onRequest: [event => {console.log("GLOBAL", event.request.url);}]});
tsx
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.