diff --git a/README.md b/README.md index f554540..41fb316 100644 --- a/README.md +++ b/README.md @@ -371,9 +371,10 @@ const server = http.createServer(app).listen(3000, () => { ViteExpress.bind(app, server); ``` -### `static() => RequestHandler` +### `static(options?: ServeStaticOptions) => RequestHandler` + +Used as a typical express middleware to indicate to `vite-express` the exact moment when you want to register static serving logic. You can use this method to prevent some of your request blocking middleware, such as authentication/authorization, from blocking files coming from your server, which would make displaying for example login page impossible because of blocked html, styles and scripts files. Another use-case is when you want to override [options][serve-static-options] that `vite-express` passes to [`express.static`](https://expressjs.com/en/starter/static-files.html) middleware in production mode. In development mode it doesn't have any effect. -Used as a typical express middleware to indicate to `vite-express` the exact moment when you want to register static serving logic. You can use this method to prevent some of your request blocking middleware, such as authentication/authorization, from blocking files coming from your server, which would make displaying for example login page impossible because of blocked html, styles and scripts files. Example: @@ -383,7 +384,7 @@ import yourAuthMiddleware from "some/path" const app = express() -app.use(ViteExpress.static()) +app.use(ViteExpress.static({ maxAge: "1d" })) app.use(yourAuthMiddleware()) app.get("/", ()=> /*...*/ ) @@ -436,3 +437,4 @@ ViteExpress.bind(app, server, async () => { [base]: https://vitejs.dev/config/shared-options.html#base [outDir]: https://vitejs.dev/config/build-options.html#build-outdir [vite-multipage]: https://vitejs.dev/guide/build.html#multi-page-app +[serve-static-options]: https://expressjs.com/en/resources/middleware/serve-static.html#options