Skip to content

Commit

Permalink
fix(storybook): serve storybook on dev environments
Browse files Browse the repository at this point in the history
Co-authored-by: chris <[email protected]>
  • Loading branch information
rbrtrfl and chohner committed Mar 22, 2024
1 parent 60940ae commit c0bf612
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
1 change: 0 additions & 1 deletion docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ case $1 in
APP_IMAGE_TAG=$APP_IMAGE

npm run build
npm run build:storybook
echo "Building $APP_IMAGE..."
docker build -t $APP_IMAGE --label "hash=$LATEST_GIT_TAG" -f $DOCKERFILE --target app --quiet .

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"build:licenses": "tsx ./app/services/openSourceLicenses/generate.server.ts generateLicenseFile",
"build:localContent": "tsx ./app/services/cms/dumpCmsToFile.ts dumpCmsToFile",
"build:pdf": "tsx ./app/services/pdf/pdf.generator.ts",
"build:storybook": "storybook build",
"build": "remix vite:build",
"build:storybook": "storybook build --output-dir ./build/client/storybook",
"build": "remix vite:build && npm run build:storybook",
"dev": "node ./server.js",
"format:fix": "prettier --write . --ignore-path .prettierignore",
"format": "prettier --check . --ignore-path .prettierignore",
Expand Down
26 changes: 17 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { createRequestHandler } from "@remix-run/express";
import compression from "compression";
import express from "express";

const viteDevServer =
process.env.NODE_ENV === "production"
? undefined
: await import("vite").then((vite) =>
vite.createServer({
server: { middlewareMode: true },
}),
);
const isProductionEnvironment = process.env.NODE_ENV === "production";

const viteDevServer = isProductionEnvironment
? undefined
: await import("vite").then((vite) =>
vite.createServer({
server: { middlewareMode: true },
}),
);

const remixHandler = createRequestHandler({
build: viteDevServer
Expand Down Expand Up @@ -37,7 +38,14 @@ if (viteDevServer) {

// Everything else (like favicon.ico) is cached for an hour. You may want to be
// more aggressive with this caching.
app.use(express.static("build/client", { maxAge: "1h" }));
const staticFileServer = express.static("build/client", { maxAge: "1h" });
const mountPathWithoutStorybook = [
/^\/build\/client\/storybook($|\/)/,
"/build/client",
];
isProductionEnvironment
? app.use(mountPathWithoutStorybook, staticFileServer)
: app.use(staticFileServer);

// handle SSR requests
app.all("*", remixHandler);
Expand Down

1 comment on commit c0bf612

@pgurusinga
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chohner does this fix the missing storybook on staging? seems I still cannot access it

Please sign in to comment.