Skip to content

Commit 2383e67

Browse files
authored
Merge pull request #915 from live-codes/local-sandbox
serve local sandbox in dev
2 parents aba5331 + 2cbf01c commit 2383e67

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"start": "run-p copy:assets watch serve",
1515
"docs": "cd docs && npm run start",
1616
"storybook": "cd storybook && npm run storybook",
17-
"serve": "live-server build --watch=build/tmp/ --cors --quiet",
17+
"serve": "run-p serve:*",
18+
"serve:app": "live-server build --watch=build/tmp/ --cors --quiet",
19+
"serve:sandbox": "live-server src/livecodes/html/sandbox/ --port=8085 --cors --quiet --no-browser",
1820
"watch": "nodemon --watch src -e \"*\" --ignore src/livecodes/i18n/locale-paths.ts ./scripts/build.js --dev",
1921
"prebuild": "npm run i18n-exclude pre",
2022
"postbuild": "npm run i18n-exclude post",

src/livecodes/services/sandbox.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@ import { sandboxVersion } from '../html/sandbox/index';
33
const cfPagesBaseUrl = 'https://livecodes-sandbox.pages.dev';
44
const ghPagesBaseUrl = 'https://live-codes.github.io/livecodes-sandbox/dist';
55
const selfHostedBaseUrl = `https://${process.env.SANDBOX_HOST_NAME}:${process.env.SANDBOX_PORT}`;
6+
const localBaseUrl = 'http://127.0.0.1:8085';
67

78
const serviceBaseUrl =
8-
process.env.SELF_HOSTED === 'true'
9-
? selfHostedBaseUrl
10-
: process.env.CI === 'true'
11-
? ghPagesBaseUrl
12-
: cfPagesBaseUrl;
9+
location.hostname === 'localhost' || location.hostname === '127.0.0.1'
10+
? localBaseUrl
11+
: process.env.SELF_HOSTED === 'true'
12+
? selfHostedBaseUrl
13+
: process.env.CI === 'true'
14+
? ghPagesBaseUrl
15+
: cfPagesBaseUrl;
1316
const version = sandboxVersion;
17+
const ext = serviceBaseUrl === localBaseUrl ? '.html' : '';
1418

1519
export const sandboxService = {
1620
getResultUrl: () => `${serviceBaseUrl}/${version}/`,
17-
getCompilerUrl: () => `${serviceBaseUrl}/${version}/compiler`,
21+
getCompilerUrl: () => `${serviceBaseUrl}/${version}/compiler${ext}`,
1822
getOrigin: () => new URL(serviceBaseUrl).origin,
1923
};

0 commit comments

Comments
 (0)