Skip to content

Commit 6af92a4

Browse files
andrewncatarak
authored andcommitted
Exposes API endpoint URL to client via env variable (#323)
1 parent 352d81e commit 6af92a4

File tree

9 files changed

+11
-7
lines changed

9 files changed

+11
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This project is currently in development! It will be announced when there is a (
1313
5. Create a file called `.env` in the root of this directory that looks like
1414

1515
```
16+
API_URL=/api
1617
MONGO_URL=mongodb://localhost:27017/p5js-web-editor
1718
PORT=8000
1819
SESSION_SECRET=whatever_you_want_this_to_be_it_only_matters_for_production
@@ -36,6 +37,7 @@ This project is currently in development! It will be announced when there is a (
3637
5. Create a file called `.env` in the root of this directory that looks like
3738

3839
```
40+
API_URL=/api
3941
MONGO_URL=mongodb://localhost:27017/p5js-web-editor
4042
PORT=8000
4143
SESSION_SECRET=make_this_a_long-random_string_like_maybe_126_characters_long

client/modules/IDE/actions/files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { reset } from 'redux-form';
55
import * as ActionTypes from '../../../constants';
66
import { setUnsavedChanges } from './ide';
77

8-
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
8+
const ROOT_URL = process.env.API_URL;
99

1010
function appendToFilename(filename, string) {
1111
const dotIndex = filename.lastIndexOf('.');

client/modules/IDE/actions/preferences.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from 'axios';
22
import * as ActionTypes from '../../../constants';
33

4-
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
4+
const ROOT_URL = process.env.API_URL;
55

66
function updatePreferences(formParams, dispatch) {
77
axios.put(`${ROOT_URL}/preferences`, formParams, { withCredentials: true })

client/modules/IDE/actions/project.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { setUnsavedChanges,
88
resetJustOpenedProject,
99
showErrorModal } from './ide';
1010

11-
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
11+
const ROOT_URL = process.env.API_URL;
1212

1313
export function setProject(project) {
1414
return {

client/modules/IDE/actions/projects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as ActionTypes from '../../../constants';
33
import { showErrorModal, setPreviousPath } from './ide';
44
import { resetProject } from './project';
55

6-
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
6+
const ROOT_URL = process.env.API_URL;
77

88
export function getProjects(username) {
99
return (dispatch) => {

client/modules/IDE/actions/uploader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createFile } from './files';
33

44
const textFileRegex = /(text\/|application\/json)/;
55
const s3BucketHttps = `https://s3-us-west-2.amazonaws.com/${process.env.S3_BUCKET}/`;
6-
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
6+
const ROOT_URL = process.env.API_URL;
77
const MAX_LOCAL_FILE_SIZE = 80000; // bytes, aka 80 KB
88

99
function localIntercept(file, options = {}) {

client/modules/User/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as ActionTypes from '../../constants';
44
import { showErrorModal, justOpenedProject } from '../IDE/actions/ide';
55

66

7-
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
7+
const ROOT_URL = process.env.API_URL;
88

99
export function authError(error) {
1010
return {

webpack.config.dev.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = {
3434
}),
3535
new webpack.DefinePlugin({
3636
'process.env': {
37+
API_URL: '"' + process.env.API_URL + '"',
3738
CLIENT: JSON.stringify(true),
3839
'NODE_ENV': JSON.stringify('development'),
3940
'S3_BUCKET': '"' + process.env.S3_BUCKET + '"'

webpack.config.prod.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module.exports = {
7676
plugins: [
7777
new webpack.DefinePlugin({
7878
'process.env': {
79+
'API_URL': '"' + process.env.API_URL + '"',
7980
'NODE_ENV': JSON.stringify('production'),
8081
'S3_BUCKET': '"' + process.env.S3_BUCKET + '"'
8182
}
@@ -112,4 +113,4 @@ module.exports = {
112113
clearMessages: true
113114
})
114115
]
115-
};
116+
};

0 commit comments

Comments
 (0)