Skip to content

Commit

Permalink
Update README with info about static options
Browse files Browse the repository at this point in the history
  • Loading branch information
szymmis committed Jun 8, 2024
1 parent b3aed7c commit 1725ce2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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("/", ()=> /*...*/ )
Expand Down Expand Up @@ -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

0 comments on commit 1725ce2

Please sign in to comment.