Skip to content

Commit a5731bf

Browse files
committed
themebuilder
1 parent ed8ee57 commit a5731bf

4 files changed

Lines changed: 23 additions & 100 deletions

File tree

Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ RUN pnpm deploy --filter=@web/www --prod /prod/@web/www
1212
RUN pnpm deploy --filter=@web/themebuilder --prod /prod/@web/themebuilder
1313

1414
FROM base AS www
15-
COPY --from=build /prod/@web/www /prod/@web/www
16-
WORKDIR /prod/@web/www
15+
COPY --from=build /prod/@web/www /srv/app
16+
WORKDIR /srv/app
17+
ENV NODE_ENV=production HOST=0.0.0.0 PORT=8000
1718
EXPOSE 8000
18-
CMD [ "pnpm", "start" ]
19+
CMD ["pnpm","start"]
1920

2021
FROM base AS themebuilder
21-
COPY --from=build /prod/@web/themebuilder /prod/@web/themebuilder
22-
WORKDIR /prod/@web/themebuilder
23-
EXPOSE 8001
22+
COPY --from=build /prod/@web/themebuilder /srv/app
23+
WORKDIR /srv/app
24+
ENV NODE_ENV=production HOST=0.0.0.0 PORT=8000
25+
EXPOSE 8000
2426
CMD [ "pnpm", "start" ]

apps/themebuilder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"build": "react-router build",
77
"dev": "react-router dev",
8-
"start": "react-router-serve ./build/server/index.js",
8+
"start": "react-router-serve ./dist/server/index.js",
99
"types": "react-router typegen && tsc"
1010
},
1111
"dependencies": {

apps/themebuilder/react-router.config.ts

Lines changed: 13 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { readFileSync, writeFileSync } from 'node:fs';
1+
import { writeFileSync } from 'node:fs';
22
import { join } from 'node:path';
33
import { cwd } from 'node:process';
44
import type { Config } from '@react-router/dev/config';
5-
import { vercelPreset } from '@vercel/react-router/vite';
6-
import { normalizePath } from 'vite';
75

86
// Ensure we always have a valid dirname, even in Vercel's environment
97
const dirname = cwd();
@@ -13,97 +11,20 @@ const config: Config = {
1311
// Server-side render by default, to enable SPA mode set this to `false`
1412
ssr: true,
1513
buildDirectory: 'dist',
16-
presets: [vercelPreset()],
17-
buildEnd: async ({ buildManifest: rrBuild }) => {
18-
const manifestPath = join(
19-
dirname,
20-
'.vercel/react-router-build-result.json',
21-
);
22-
23-
/* read file contents */
24-
const newBuildResult: {
25-
// biome-ignore lint/suspicious/noExplicitAny: Won't bother with type since vercel might change it
26-
buildManifest?: { serverBundles?: any; routes?: any };
27-
viteConfig?: { ssr?: { noExternal?: string[] } };
28-
reactRouterConfig?: typeof rrBuild & {
29-
appDirectory?: string;
30-
buildDirectory?: string;
31-
};
32-
} = {};
33-
try {
34-
const fileContents = readFileSync(manifestPath, 'utf-8');
35-
newBuildResult.buildManifest = JSON.parse(fileContents).buildManifest;
36-
newBuildResult.viteConfig = JSON.parse(fileContents).viteConfig;
37-
} catch (error) {
38-
console.error(`Error reading manifest file: ${error}`);
39-
return;
40-
}
41-
42-
/* For every item in buildmanifest.serverBundles, add config.runtime = "nodejs" */
43-
if (newBuildResult.buildManifest?.serverBundles) {
44-
// Use Object.values to get an array of the serverBundles objects
45-
for (const bundle of Object.values(
46-
newBuildResult.buildManifest.serverBundles,
47-
)) {
48-
const typedBundle = bundle as { config?: { runtime?: string } };
49-
typedBundle.config = typedBundle.config || {};
50-
typedBundle.config.runtime = 'nodejs';
51-
}
52-
}
53-
54-
/* For every item in buildmanifest.routes, add config.runtime = "nodejs" */
55-
if (newBuildResult.buildManifest?.routes) {
56-
// Use Object.values to get an array of the routes objects
57-
for (const route of Object.values(newBuildResult.buildManifest.routes)) {
58-
const typedRoute = route as { config?: { runtime?: string } };
59-
typedRoute.config = typedRoute.config || {};
60-
(route as { config: { runtime: string } }).config.runtime = 'nodejs';
61-
}
62-
}
63-
64-
if (!rrBuild) {
65-
console.error(
66-
'No react-router build result found. Skipping Vercel config update.',
67-
);
68-
return;
69-
}
70-
71-
newBuildResult.reactRouterConfig = rrBuild || {};
72-
newBuildResult.reactRouterConfig.appDirectory = normalizePath(
73-
join(dirname, 'app'),
74-
);
75-
newBuildResult.reactRouterConfig.buildDirectory = normalizePath(
76-
join(dirname, 'dist'),
77-
);
78-
79-
// write back to the file
14+
presets: [],
15+
buildEnd: async () => {
16+
const robotsPath = join(dirname, 'public', 'robots.txt');
17+
const robotsContent =
18+
process.env.VERCEL_ENV === 'production'
19+
? `User-agent: *\nAllow: /`
20+
: `User-agent: *\nDisallow: /`;
21+
22+
console.log(`Writing robots.txt to ${robotsPath}`);
8023
try {
81-
writeFileSync(manifestPath, JSON.stringify(newBuildResult, null, 2));
24+
writeFileSync(robotsPath, robotsContent);
8225
} catch (error) {
83-
console.error(`Error writing manifest file: ${error}`);
84-
}
85-
86-
if (process.env.VERCEL_ENV === 'production') {
87-
const robotsPath = join(dirname, 'public', 'robots.txt');
88-
const robotsContent = `User-agent: *\nAllow: /`;
89-
90-
console.log(`Writing production robots.txt to ${robotsPath}`);
91-
try {
92-
writeFileSync(robotsPath, robotsContent);
93-
} catch (error) {
94-
console.error(`Error writing robots.txt file: ${error}`);
95-
throw new Error(`Failed to write robots.txt file: ${error}`);
96-
}
97-
} else {
98-
const robotsPath = join(dirname, 'public', 'robots.txt');
99-
const robotsContent = `User-agent: *\nDisallow: /`;
100-
101-
console.log(`Writing preview robots.txt to ${robotsPath}`);
102-
try {
103-
writeFileSync(robotsPath, robotsContent);
104-
} catch (error) {
105-
console.error(`Error writing robots.txt file: ${error}`);
106-
}
26+
console.error(`Error writing robots.txt file: ${error}`);
27+
throw new Error(`Failed to write robots.txt file: ${error}`);
10728
}
10829
},
10930
};

apps/www/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"build": "react-router typegen && react-router build && node scripts/copy-content.js",
77
"dev": "react-router dev",
8-
"start": "react-router-serve ./dist/server/nodejs_eyJydW50aW1lIjoibm9kZWpzIn0/index.js",
8+
"start": "react-router-serve ./dist/server/index.js",
99
"types": "react-router typegen && tsc"
1010
},
1111
"dependencies": {

0 commit comments

Comments
 (0)