Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced BASE_URL environment variable #288

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 95 additions & 95 deletions dist/index.js

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,16 @@ Setting a wildcard (`*`) is also supported, but not recommended. It's neither a

```
ACKEE_ALLOW_ORIGIN="*"
```
```

## Base URL

As an alternative to masking with a reverse proxy, you can use the base URL environment variable like so

```
BASE_URL=/ackee
```

Because when Ackee builds the index.html it needs to know where to retrieve index.js, style.css etc. from, base URL allows you to serve Ackee on a route other than index.

Note, that because `dist` is already built when you clone the repo, you'll need to run `npm run build:pre` and rebuild the entire dist rather than just the index. This is particularly important because the route on which index.js is served, is also the route to which you will want to post API requests e.g. `/ackee/api`.
4 changes: 2 additions & 2 deletions src/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const customTracker = require('../utils/customTracker')
const signale = require('../utils/signale')

const index = () => {
return layout('<div id="main"></div>', 'favicon.ico', [ 'index.css' ], [ 'index.js' ], {
return layout('<div id="main"></div>', `${ config.baseUrl }/favicon.ico`, [ `${ config.baseUrl }/index.css` ], [ `${ config.baseUrl }/index.js` ], {
isDemoMode: config.isDemoMode,
customTracker,
})
Expand All @@ -29,7 +29,7 @@ const scripts = () => {
return js(filePath, {
optimize: config.isDevelopmentMode === false,
nodeGlobals: config.isDevelopmentMode === true,
replace: { 'process.env.NODE_ENV': JSON.stringify(config.isDevelopmentMode === true ? 'development' : 'production') },
replace: { 'process.env.NODE_ENV': JSON.stringify(config.isDevelopmentMode === true ? 'development' : 'production'), 'process.env.BASE_URL': config.baseUrl },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this up to the index function. The last argument of the layout function accepts environment variables that you can access via window.env in the UI scripts.

babel: false,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/scripts/api/links/createHttpLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userTimeZone from '../../../../utils/timeZone'

export default () => {
return new BatchHttpLink({
uri: '/api',
uri: 'process.env.BASE_URL/api',
headers: {
'Time-Zone': userTimeZone,
},
Expand Down
1 change: 1 addition & 0 deletions src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = new Proxy({}, {
ttl: process.env.ACKEE_TTL || day,
port: process.env.ACKEE_PORT || process.env.PORT || 3000,
dbUrl: process.env.ACKEE_MONGODB || process.env.MONGODB_URI,
baseUrl: process.env.BASE_URL || '',
allowOrigin: process.env.ACKEE_ALLOW_ORIGIN,
username: process.env.ACKEE_USERNAME,
password: process.env.ACKEE_PASSWORD,
Expand Down