Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Add env var to control API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb committed Apr 25, 2020
1 parent 04a19ac commit c8f766a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.DS_Store
build
.env.local

### Django ###
*.log
Expand Down
1 change: 1 addition & 0 deletions webapp/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_ENDPOINT=http://localhost:8000
67 changes: 6 additions & 61 deletions webapp/README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,13 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts
## Running the app in development mode

In the project directory, you can run:
First, copy `.env.example` to `.env.local` and change the endpoint variable if necessary.

### `npm start`
Then, run `npm start`.

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
## Building the app for production

The page will reload if you make edits.<br />
You will also see any lint errors in the console.
Set the environment variables (in `.env.example`) in some way so that they will be available during the build.

### `npm test`

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `npm run build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
Then, run `npm run build`. It will output artifacts to the `./build` directory.
Empty file removed webapp/index.js
Empty file.
5 changes: 4 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"rules": {
"react/prop-types": "off",
"default-param-last": "off"
}
},
"ignores": [
"build"
]
},
"eslintConfig": {
"extends": [
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const ENDPOINT = process.env.REACT_APP_ENDPOINT;

export {ENDPOINT};
3 changes: 2 additions & 1 deletion webapp/src/store/actions/courses.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {createAction} from 'redux-api-middleware';
import {ENDPOINT} from '../../config';

export const GET_COURSES_REQUEST = 'GET_COURSES_REQUEST';
export const GET_COURSES_SUCCESS = 'GET_COURSES_SUCCESS';
export const GET_COURSES_ERROR = 'GET_COURSES_ERROR';

export const getCourses = () => createAction({
endpoint: 'http://localhost:8000/api/courses/?limit=11000',
endpoint: `${ENDPOINT}/api/courses/?limit=11000`,
method: 'GET',
types: [
'GET_COURSES_REQUEST',
Expand Down

0 comments on commit c8f766a

Please sign in to comment.