Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ServeStaticOptions

Options for the serveStatic method.

Hierarchy

  • ServeStaticOptions

Index

Properties

Optional exclude

exclude: string[]

List of excluded files that should not be served

Optional expiresSeconds

expiresSeconds: undefined | number

The time in seconds that the statically rendered response is considered valid. Must be a positive number. If it's not specified the rendered response never expires.

Optional loadingPage

loadingPage: undefined | string

The path to a statically rendered loading page to be served when falling back to compute. By specifying both loadingPage and onNotFound, when a request cannot be fulfilled with a static asset, Edgio will instantly serve a loading page while computing a server-side rendered result for future requests. This ensures that all requests will have a low time-to-first-byte (TTFB) and no user will need to wait for SSR to finish before seeing something in their browser.

Example:

 router.get('/products/:id', res => {
   res.serveStatic('dist/products/:id.html', {
     onNotFound: () => res.renderWithApp(), // fall back to server-side rendering
     loadingPage: 'dist/products/loading.html' // show the loading page while SSR is in progress
   })
 })

Note that it's up to your front-end code to fetch the data to render the full page when the loading page is served. Frameworks like Next.js, for example, do this automatically when you use getStaticPaths with fallback: true.

Optional onNotFound

onNotFound: undefined | ((res: ResponseWriter) => Promise<void>)

A function to run when no static asset exists at the specified path. Use this option to perform server-side rendering for URLs that are not statically rendered at build-time.

Example:

 router.get('/products/:id', res => {
   res.serveStatic('dist/products/:id.html', {
     onNotFound: () => res.renderWithApp() // fall back to server-side rendering
   })
 })

Because SSR can often be slow, we recommend using this option in conjunction with loadingPage so that users do not have to wait for SSR to finish before seeing something in their browser.

Optional permanent

permanent: undefined | false | true

When true, assets are served from a bucket/prefix that remains available across all builds on a given environment.

Optional statusCode

statusCode: undefined | number

Sets the status code for the response. If not specified, the status code will be 200.

Optional statusMessage

statusMessage: undefined | string

Sets the status code for the response. If not specified, the status message will be "OK".

Generated using TypeDoc