Skip to content

Commit

Permalink
feat(app-webpack): SSR/webserver -> returned fn from serveStaticConte…
Browse files Browse the repository at this point in the history
…nt can now be async too
  • Loading branch information
rstoenescu committed Aug 2, 2024
1 parent 3395c22 commit 95712f8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app-webpack/templates/entry/ssr-prod-webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export async function startServer () {

<% if (ssr.pwa) { %>
// serve the service worker with no cache
serveStatic({ urlPath: '/<%= pwa.swFilename %>', pathToServe: '<%= pwa.swFilename %>', opts: { maxAge: 0 } })
await serveStatic({ urlPath: '/<%= pwa.swFilename %>', pathToServe: '<%= pwa.swFilename %>', opts: { maxAge: 0 } })
<% } %>

// serve "client" folder (includes the "public" folder)
serveStatic({ urlPath: '/', pathToServe: '.' })
await serveStatic({ urlPath: '/', pathToServe: '.' })

await injectMiddlewares(middlewareParams)

Expand Down
3 changes: 3 additions & 0 deletions app-webpack/templates/ssr/default/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ const maxAge = process.env.DEV
* to serve static content at "urlPath" from "pathToServe" folder/file.
*
* Notice resolve.urlPath(urlPath) and resolve.public(pathToServe) usages.
*
* Can be async: ssrServeStaticContent(async ({ app, resolve }) => {
* Can return an async function: return async ({ urlPath = '/', pathToServe = '.', opts = {} }) => {
*/
export const serveStaticContent = ssrServeStaticContent(({ app, resolve }) => {
return ({ urlPath = '/', pathToServe = '.', opts = {} }) => {
Expand Down
3 changes: 3 additions & 0 deletions app-webpack/templates/ssr/ts/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ const maxAge = process.env.DEV ? 0 : 1000 * 60 * 60 * 24 * 30;
* to serve static content at "urlPath" from "pathToServe" folder/file.
*
* Notice resolve.urlPath(urlPath) and resolve.public(pathToServe) usages.
*
* Can be async: ssrServeStaticContent(async ({ app, resolve }) => {
* Can return an async function: return async ({ urlPath = '/', pathToServe = '.', opts = {} }) => {
*/
export const serveStaticContent = ssrServeStaticContent(({ app, resolve }) => {
return ({ urlPath = '/', pathToServe = '.', opts = {} }) => {
Expand Down
2 changes: 1 addition & 1 deletion app-webpack/types/ssrmiddleware.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ interface SsrServeStaticFnParams {
opts?: ServeStaticOptions<Response>;
}

type SsrServeStaticFn = (params: SsrServeStaticFnParams) => void;
type SsrServeStaticFn = (params: SsrServeStaticFnParams) => void | Promise<void>;

export type SsrServeStaticContentCallback = (
params: ssrServeStaticContentParams
Expand Down

0 comments on commit 95712f8

Please sign in to comment.