Skip to content

Commit 0d77b7e

Browse files
committed
switched to .env for variables
1 parent aeec589 commit 0d77b7e

File tree

7 files changed

+41
-19
lines changed

7 files changed

+41
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ npm-*
2626

2727
# for act
2828
.secrets
29+
.env

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696
"scratch-blocks": "github:CodeTorchNET/scratch-blocks#develop",
9797
"scratch-paint": "github:CodeTorchNET/scratch-paint#develop",
9898
"scratch-render": "github:CodeTorchNET/scratch-render#develop",
99-
"scratch-vm": "github:CodeTorchNET/scratch-vm#develop",
10099
"scratch-storage": "github:CodeTorchNET/scratch-storage#develop",
100+
"scratch-vm": "github:CodeTorchNET/scratch-vm#develop",
101101
"showdown": "^2.1.0",
102102
"simplex-noise": "^4.0.3",
103103
"style-loader": "^0.23.0",
@@ -125,6 +125,7 @@
125125
"babel-eslint": "10.1.0",
126126
"babel-loader": "8.3.0",
127127
"chromedriver": "117.0.3",
128+
"dotenv": "^17.2.3",
128129
"enzyme": "3.10.0",
129130
"enzyme-adapter-react-16": "1.15.7",
130131
"eslint": "8.55.0",

src/addons/addons/collaboration/helpers/constants.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,17 @@ import CollaborationConsole from './CollaborationConsole.js';
88
*/
99
export const debugging = true;
1010

11-
export const apiHostURL =
12-
["localhost", "127.0.0.1", "::1"].includes(window.location.hostname)
13-
? "http://localhost:8000"
14-
: "https://api.codetorch.net";
15-
11+
export const apiHostURL = process.env.API_HOST;
1612
/**
1713
* Development Mode.
1814
* Set to `true` to allow the addon to run even if window.CollaborationRoom/OTT are undefined.
1915
*/
20-
export const devMode =
21-
["localhost", "127.0.0.1", "::1"].includes(window.location.hostname)
22-
? true
23-
: false;
16+
export const devMode = process.env.COLLABORATION_DEV_MODE === 'true';
2417

2518
/**
2619
* The base URL for the WebSocket server used for Yjs collaboration.
2720
*/
28-
export const WEBSOCKETBASEURL = 'ws://localhost:4444';
21+
export const WEBSOCKETBASEURL = process.env.COLLABORATION_HOST;
2922

3023
/**
3124
* Inactivity thresholds in milliseconds.

src/lib/brand.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Legacy export format because this is used by some build-time scripts stuck in the past.
22
// eslint-disable-next-line import/no-commonjs
33
module.exports = {
4-
APP_NAME: 'CodeTorch',
5-
APP_DOMAIN: 'http://localhost:8080',
6-
API_HOST: 'http://localhost:8000',
7-
ASSET_HOST: 'http://localhost:8000',
8-
EXTENSION_HOST: 'http://localhost:8002',
9-
DEFAULT_CLOUD_HOST: 'ws://localhost:8001',
4+
APP_NAME: process.env.APP_NAME,
5+
APP_DOMAIN: process.env.APP_DOMAIN,
6+
API_HOST: process.env.API_HOST,
7+
ASSET_HOST: process.env.ASSET_HOST,
8+
EXTENSION_HOST: process.env.EXTENSION_HOST,
9+
DEFAULT_CLOUD_HOST: process.env.DEFAULT_CLOUD_HOST,
10+
TRUSTED_IFRAME_HOST: process.env.TRUSTED_IFRAME_HOST,
1011
enableGenerate: false
1112
};

src/playground/render-interface.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {APP_NAME} from '../lib/brand.js';
3737

3838
import styles from './interface.css';
3939

40-
const isInvalidEmbed = window.parent === window;
40+
const isInvalidEmbed = process.env.FORCE_EMBED === 'true' ? window.parent === window : false;
4141

4242
const handleClickAddonSettings = () => {
4343
// addonId might be a string of the addon to focus on, undefined, or an event (treat like undefined)

webpack.config.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const defaultsDeep = require('lodash.defaultsdeep');
22
const path = require('path');
33
const webpack = require('webpack');
44

5+
require('dotenv').config();
6+
57
// Plugins
68
const CopyWebpackPlugin = require('copy-webpack-plugin');
79
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -183,7 +185,18 @@ module.exports = [
183185
'process.env.DEBUG': Boolean(process.env.DEBUG),
184186
'process.env.ENABLE_SERVICE_WORKER': JSON.stringify(process.env.ENABLE_SERVICE_WORKER || ''),
185187
'process.env.ROOT': JSON.stringify(root),
186-
'process.env.ROUTING_STYLE': JSON.stringify(process.env.ROUTING_STYLE || 'filehash')
188+
'process.env.ROUTING_STYLE': JSON.stringify(process.env.ROUTING_STYLE || 'filehash'),
189+
190+
'process.env.APP_NAME': JSON.stringify(process.env.APP_NAME || 'CodeTorch'),
191+
'process.env.APP_DOMAIN': JSON.stringify(process.env.APP_NAME || 'https://codetorch.net'),
192+
'process.env.API_HOST': JSON.stringify(process.env.API_HOST || 'https://api.codetorch.net'),
193+
'process.env.ASSET_HOST': JSON.stringify(process.env.ASSET_HOST || 'https://assets.scratch.mit.edu'),
194+
'process.env.EXTENSION_HOST': JSON.stringify(process.env.EXTENSION_HOST || 'https://blockextensions.codetorch.net'),
195+
'process.env.DEFAULT_CLOUD_HOST': JSON.stringify(process.env.DEFAULT_CLOUD_HOST || 'wss://cloud.codetorch.org'),
196+
'process.env.TRUSTED_IFRAME_HOST': JSON.stringify(process.env.TRUSTED_IFRAME_HOST || 'https://codetorch.net'),
197+
'process.env.FORCE_EMBED': JSON.stringify(process.env.FORCE_EMBED || 'true'),
198+
'process.env.COLLABORATION_HOST': JSON.stringify(process.env.COLLABORATION_HOST || 'wss://collaborator.codetorch.net/'),
199+
'process.env.COLLABORATION_DEV_MODE': JSON.stringify(process.env.COLLABORATION_DEV_MODE || 'false')
187200
}),
188201
new HtmlWebpackPlugin({
189202
chunks: ['editor'],

0 commit comments

Comments
 (0)