Skip to content

Commit 1f140a1

Browse files
authored
Add stream option flag (codesandbox#3290)
* Default to stream * Make it a flag * Rename env var * Update cli login url to reflect stream
1 parent 2bcd8e7 commit 1f140a1

File tree

8 files changed

+33
-10
lines changed

8 files changed

+33
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"start:dev_api": "concurrently --raw \"cd packages/app && yarn start:dev_api\" \"cd packages/common && yarn start\" \"cd packages/components && yarn start\"",
5151
"start:dynamic": "lerna run dev --scope dynamic-pages --stream",
5252
"start:fast": "concurrently --raw \"cd packages/app && yarn start\" \"cd packages/common && yarn start\" \"cd packages/components && yarn start\"",
53+
"start:fast:stream": "cross-env STAGING_API=1 concurrently --raw \"cd packages/app && yarn start\" \"cd packages/common && yarn start\" \"cd packages/components && yarn start\"",
5354
"start:home": "yarn build:deps && yarn start:home:fast",
5455
"start:home:fast": "cd packages/homepage && yarn start",
5556
"start:overmind": "yarn build:deps && concurrently \"lerna run start --scope app --stream\" \"overmind-devtools\"",

packages/app/scripts/start.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ const { staticAssets } = require('../config/build');
2020

2121
// Tools like Cloud9 rely on this.
2222
var DEFAULT_PORT = process.env.PORT || 3000;
23-
const PROXY_DOMAIN = 'https://codesandbox.io';
23+
const PROXY_DOMAIN = process.env.STAGING_API
24+
? 'https://codesandbox.stream'
25+
: 'https://codesandbox.io';
2426
var compiler;
2527
var handleCompile;
2628
var compileStart;

packages/app/src/app/pages/DevAuth/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ export const DevAuthPage = () => {
4444
});
4545
};
4646

47+
const baseSignInDomain = process.env.STAGING_API
48+
? 'https://codesandbox.stream'
49+
: 'https://codesandbox.io';
50+
const cliLoginUrl = `${baseSignInDomain}/cli/login`;
4751
return (
4852
<Container>
4953
<Title>Developer Sign In</Title>
5054
<SubTitle style={{ width: 800 }}>
5155
Please enter the token you get from{' '}
5256
<a
53-
href="https://codesandbox.io/cli/login"
57+
href={cliLoginUrl}
5458
target="popup"
5559
rel="noreferrer noopener"
5660
onClick={e => {
5761
e.preventDefault();
58-
window.open(
59-
'https://codesandbox.io/cli/login',
60-
'popup',
61-
'width=600,height=600'
62-
);
62+
window.open(cliLoginUrl, 'popup', 'width=600,height=600');
6363
return false;
6464
}}
6565
>

packages/app/src/app/utils/executor-manager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,14 @@ export class ExecutorsManager {
7474
this.executor = new ExecutorType();
7575
}
7676

77+
const sseHost = process.env.STAGING_API
78+
? 'https://codesandbox.stream'
79+
: 'https://codesandbox.io';
80+
7781
await this.executor.initialize({
7882
sandboxId: sandbox.id,
7983
files: getModulesToSend(sandbox),
84+
host: sseHost,
8085
});
8186

8287
return this.executor;

packages/common/src/components/Preview/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ type State = {
6464
useFallbackDomain: boolean;
6565
};
6666

67+
const sseDomain = process.env.STAGING_API
68+
? 'codesandbox.stream'
69+
: 'codesandbox.io';
70+
6771
const getSSEUrl = (sandbox?: Sandbox, initialPath: string = '') =>
6872
`https://${sandbox ? `${sandbox.id}.` : ''}sse.${
6973
process.env.NODE_ENV === 'development' || process.env.STAGING
70-
? 'codesandbox.io'
74+
? sseDomain
7175
: host()
7276
}${initialPath}`;
7377

packages/common/src/config/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import getHost from '../utils/host';
55
const REACT_APP = /^REACT_APP_/i;
66
const NODE_ENV = JSON.stringify(process.env.NODE_ENV || 'development');
77
const LOCAL_SERVER = Boolean(JSON.stringify(process.env.LOCAL_SERVER));
8+
const STAGING_API = Boolean(JSON.stringify(process.env.STAGING_API));
89

910
export default Object.keys(process.env)
1011
.filter(key => REACT_APP.test(key))
@@ -15,6 +16,7 @@ export default Object.keys(process.env)
1516
},
1617
{
1718
'process.env.NODE_ENV': NODE_ENV,
19+
'process.env.STAGING_API': STAGING_API,
1820
'process.env.CODESANDBOX_HOST': JSON.stringify(getHost()),
1921
'process.env.LOCAL_SERVER': Boolean(LOCAL_SERVER),
2022
'process.env.STAGING': 'STAGING_BRANCH' in process.env,

packages/executors/src/executor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export interface IFiles {
88
}
99

1010
export interface ISetupParams {
11+
/**
12+
* Eg. https://codesandbox.io
13+
*/
14+
host: string;
1115
files: IFiles;
1216
sandboxId: string;
1317
}

packages/executors/src/serverExecutor.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export class ServerExecutor implements IExecutor {
6363
socket: SocketIOClient.Socket;
6464
connectTimeout: number | null = null;
6565
token: Promise<string | undefined>;
66+
host?: string;
6667
sandboxId?: string;
6768
lastSent?: IFiles;
6869

@@ -72,17 +73,21 @@ export class ServerExecutor implements IExecutor {
7273
}
7374

7475
private initializeSocket() {
75-
return io(`https://sse.codesandbox.io`, {
76+
const usedHost = this.host || 'https://codesandbox.io';
77+
const sseHost = usedHost.replace('https://', 'https://sse.');
78+
79+
return io(sseHost, {
7680
autoConnect: false,
7781
transports: ['websocket', 'polling'],
7882
});
7983
}
8084

81-
async initialize({ sandboxId, files }: ISetupParams) {
85+
async initialize({ sandboxId, files, host }: ISetupParams) {
8286
if (this.sandboxId === sandboxId && this.socket.connected) {
8387
return;
8488
}
8589

90+
this.host = host;
8691
this.sandboxId = sandboxId;
8792
this.lastSent = files;
8893

0 commit comments

Comments
 (0)