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

Add variable to support prefixPath for the cadence web-UI #576

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ COPY . .
RUN npm install --no-save --production --unsafe-perm

# Bundle the client code
ARG PREFIX_PATH
ENV PREFIX_PATH=$PREFIX_PATH
RUN npm run build-production

# switch to lite version of node
Expand Down
1 change: 1 addition & 0 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
import { injectMomentDurationFormat, jsonTryParse } from '~helpers';

const routeOpts = {
base: process.env.PREFIX_PATH,
mode: 'history',
routes: [
{
Expand Down
8 changes: 7 additions & 1 deletion client/services/http-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ class HttpService {
}

async request(baseUrl, { query, ...options } = {}) {
const { origin } = this;
let { origin } = this;
const fetch = this.fetchOverride ? this.fetchOverride : window.fetch;
const queryString = getQueryStringFromObject(query);
const path = queryString ? `${baseUrl}${queryString}` : baseUrl;
const hasOrigin = baseUrl.startsWith('http');
const prefixPath = process.env.PREFIX_PATH;

if (!origin.endsWith(prefixPath)) {
origin = `${origin}${prefixPath}`.replace(/\/$/, '');
Copy link
Contributor

Choose a reason for hiding this comment

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

adding path to origin is misleading, managing the path is more accurate

}

const url = hasOrigin ? path : `${origin}${path}`;
const isCrossOrigin = !url.startsWith(window.location.origin);

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"koa-better-error-handler": "^1.3.0",
"koa-bodyparser": "^4.2.0",
"koa-compress": "^2.0.0",
"koa-mount": "^4.0.0",
"koa-onerror": "^3.1.0",
"koa-router": "^7.2.1",
"koa-send": "^4.1.1",
Expand Down
21 changes: 14 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
var app = require('./server/index'),
port = Number(process.env.CADENCE_WEB_PORT) || 8088,
production = process.env.NODE_ENV === 'production'
const mount = require('koa-mount');
const Koa = require('koa');
const cadenceWeb = require('./server/index'),
port = Number(process.env.CADENCE_WEB_PORT) || 8088,
production = process.env.NODE_ENV === 'production';

app.init().listen(port)
const app = new Koa();
const appPrefixPath = process.env.PREFIX_PATH || '/'

app.use(mount(appPrefixPath, cadenceWeb.init()));
Copy link
Contributor

Choose a reason for hiding this comment

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

This middleware needs to get added inside server/index and used as part of the app init. The server/index acts as the entrypoint if you are installing cadence-web as a dependency package. (more about it here)

app.listen(port);

console.log('cadence-web up and listening on port ' + port);

console.log('cadence-web up and listening on port ' + port)
if (!production) {
console.log('webpack is compiling...')
}
console.log('webpack is compiling...');
}
13 changes: 10 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const
ExtractTextPlugin = require('extract-text-webpack-plugin'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
extractStylus = 'css-loader?sourceMap!stylus-loader',
development = !['production', 'ci'].includes(process.env.NODE_ENV)
development = !['production', 'ci'].includes(process.env.NODE_ENV),
appPrefixPath = process.env.PREFIX_PATH || '/'

require('babel-polyfill');

Expand All @@ -17,12 +18,18 @@ module.exports = {
output: {
path: path.join(__dirname, 'dist'),
filename: 'cadence.[hash].js',
publicPath: '/'
publicPath: appPrefixPath
},
plugins: [
!development && new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
NODE_ENV: '"production"',
PREFIX_PATH: `"${appPrefixPath}"`
}
}),
development && new webpack.DefinePlugin({
'process.env': {
PREFIX_PATH: `"${appPrefixPath}"`
}
}),
new ExtractTextPlugin({ filename: development ? 'cadence.css' : 'cadence.[hash].css', allChunks: true }),
Expand Down