Skip to content

Commit 443d65c

Browse files
authored
chore: FIT-14: Ensure production deployment of playground is resolvable as a subpath redirect (#7595)
1 parent a7f016e commit 443d65c

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

web/apps/playground/project.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"defaultConfiguration": "production",
1111
"options": {
1212
"compiler": "babel",
13-
"outputPath": "dist/apps/playground",
13+
"outputPath": "dist/apps/playground/playground-assets",
1414
"index": "apps/playground/src/index.html",
1515
"baseHref": "/",
1616
"main": "apps/playground/src/main.tsx",
@@ -26,7 +26,8 @@
2626
"extractLicenses": false,
2727
"optimization": false,
2828
"sourceMap": true,
29-
"vendorChunk": true
29+
"vendorChunk": true,
30+
"baseHref": "/"
3031
},
3132
"production": {
3233
"fileReplacements": [
@@ -39,7 +40,8 @@
3940
"sourceMap": false,
4041
"namedChunks": false,
4142
"extractLicenses": true,
42-
"vendorChunk": false
43+
"vendorChunk": false,
44+
"baseHref": "/playground-assets/"
4345
}
4446
}
4547
},

web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
"extract-antd-no-reset": "nx extract-antd-no-reset editor",
3838
"storybook:serve": "nx storybook storybook",
3939
"storybook:build": "nx build-storybook storybook",
40-
"playground:serve": "FRONTEND_HOSTNAME=http://localhost:4200 MODE=standalone nx run playground:serve:development",
41-
"playground:build": "NODE_ENV=production MODE=standalone nx run playground:build:production"
40+
"playground:serve": "FRONTEND_HOSTNAME=http://localhost:4200 MODE=standalone-playground nx run playground:serve:development",
41+
"playground:build": "NODE_ENV=production MODE=standalone-playground nx run playground:build:production && mv dist/apps/playground/playground-assets/index.html dist/apps/playground/index.html"
4242
},
4343
"husky": {
4444
"hooks": {

web/webpack.config.js

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const optimizer = () => {
6565
result.minimizer = undefined;
6666
}
6767

68-
if (process.env.MODE === "standalone") {
68+
if (process.env.MODE.startsWith("standalone")) {
6969
result.runtimeChunk = false;
7070
result.splitChunks = { cacheGroups: { default: false } };
7171
}
@@ -84,7 +84,7 @@ module.exports = composePlugins(
8484
withReact({ svgr: true }),
8585
(config) => {
8686
// LS entrypoint
87-
if (process.env.MODE !== "standalone") {
87+
if (!process.env.MODE.startsWith("standalone")) {
8888
config.entry = {
8989
main: {
9090
import: path.resolve(__dirname, "apps/labelstudio/src/main.tsx"),
@@ -94,7 +94,12 @@ module.exports = composePlugins(
9494
config.output = {
9595
...config.output,
9696
uniqueName: "labelstudio",
97-
publicPath: isDevelopment && FRONTEND_HOSTNAME ? `${FRONTEND_HOSTNAME}/react-app/` : "auto",
97+
publicPath:
98+
isDevelopment && FRONTEND_HOSTNAME
99+
? `${FRONTEND_HOSTNAME}/react-app/`
100+
: process.env.MODE === "standalone-playground"
101+
? "/playground-assets/"
102+
: "auto",
98103
scriptType: "text/javascript",
99104
};
100105

@@ -265,38 +270,37 @@ module.exports = composePlugins(
265270
mode,
266271
plugins,
267272
optimization: optimizer(),
268-
devServer:
269-
process.env.MODE === "standalone"
270-
? {}
271-
: {
272-
// Port for the Webpack dev server
273-
port: HMR_PORT,
274-
// Enable HMR
275-
hot: true,
276-
// Allow cross-origin requests from Django
277-
headers: { "Access-Control-Allow-Origin": "*" },
278-
static: {
279-
directory: path.resolve(__dirname, "../label_studio/core/static/"),
280-
publicPath: "/static/",
281-
},
282-
devMiddleware: {
283-
publicPath: `${FRONTEND_HOSTNAME}/react-app/`,
273+
devServer: process.env.MODE.startsWith("standalone")
274+
? {}
275+
: {
276+
// Port for the Webpack dev server
277+
port: HMR_PORT,
278+
// Enable HMR
279+
hot: true,
280+
// Allow cross-origin requests from Django
281+
headers: { "Access-Control-Allow-Origin": "*" },
282+
static: {
283+
directory: path.resolve(__dirname, "../label_studio/core/static/"),
284+
publicPath: "/static/",
285+
},
286+
devMiddleware: {
287+
publicPath: `${FRONTEND_HOSTNAME}/react-app/`,
288+
},
289+
allowedHosts: "all", // Allow access from Django's server
290+
proxy: {
291+
"/api": {
292+
target: `${DJANGO_HOSTNAME}/api`,
293+
changeOrigin: true,
294+
pathRewrite: { "^/api": "" },
295+
secure: false,
284296
},
285-
allowedHosts: "all", // Allow access from Django's server
286-
proxy: {
287-
"/api": {
288-
target: `${DJANGO_HOSTNAME}/api`,
289-
changeOrigin: true,
290-
pathRewrite: { "^/api": "" },
291-
secure: false,
292-
},
293-
"/": {
294-
target: `${DJANGO_HOSTNAME}`,
295-
changeOrigin: true,
296-
secure: false,
297-
},
297+
"/": {
298+
target: `${DJANGO_HOSTNAME}`,
299+
changeOrigin: true,
300+
secure: false,
298301
},
299302
},
303+
},
300304
});
301305
},
302306
);

0 commit comments

Comments
 (0)