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

Support API prefix #191

Open
wants to merge 3 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
7 changes: 4 additions & 3 deletions app/services/base_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ axios.defaults.headers.common['Accept'] = 'application/json';
export default class BaseService {
baseUrl() {
let settings = store.get('settings');

return URI("")
.host(settings.API_URL)
.scheme(`${settings.SECURE_HTTP ? 'https' : 'http'}`);
}

get(segment, ...params) {
return axios.get(this.baseUrl().segment(segment), ...params);
let settings = store.get('settings');
return axios.get(this.baseUrl().segment([settings.API_PATH].concat(segment)), ...params);
}

post(segment, data, ...params) {
return axios.post(this.baseUrl().segment(segment), data, ...params);
let settings = store.get('settings');
return axios.post(this.baseUrl().segment([settings.API_PATH].concat(segment)), data, ...params);
}
}
5 changes: 2 additions & 3 deletions app/services/real-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ function real_time_factory() {
var url = URI("")
.host(settings.API_URL)
.scheme(`${settings.SECURE_HTTP ? 'https' : 'http'}`)
.segment(['events'])
.segment([settings.API_PATH, 'events'])
.search({'token': token});
var source = new EventSource(url);
} else {
var url = URI("")
.host(settings.API_URL)
.scheme(`${settings.SECURE_HTTP ? 'wss' : 'ws'}`)
.segment(['all_events', token]);

.segment([settings.API_PATH, 'all_events', token]);
var source = new WebSocket(url);
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@
"express": "",
"form-urlencoded": "",
"html-webpack-plugin": "",
"extract-text-webpack-plugin": ">=1.0.1",
"extract-text-webpack-plugin": ">=2.0.0-rc.3",
"cosmos-js": "^0.7.0",
"yargs": "^3.30.0"
},
"scripts": {
"clean": "rimraf dist && rimraf dist.zip",
"build:webpack": "NODE_ENV=production ./node_modules/webpack/bin/webpack.js --config webpack.config.prod.js",
"build": "npm run clean && npm run build:webpack && zip -r dist.zip dist/* && md5sum dist.zip > dist.zip.md5 && sha1sum dist.zip > dist.zip.sha1",
"build:webpack:dev": "NODE_ENV=production ./node_modules/webpack/bin/webpack.js --config webpack.config.dev.js",
"build:dev": "npm run clean && npm run build:webpack:dev && zip -r dist.zip dist/* && md5sum dist.zip > dist.zip.md5 && sha1sum dist.zip > dist.zip.sha1",
"start": "node devServer.js",
"playground": "node devServer.js --env playground",
"lint": "eslint src"
Expand Down
3 changes: 2 additions & 1 deletion settings.json.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"API_URL": "localhost:5417", # The API URL
"API_PATH": "/", # The API path
"SECURE_HTTP": false, # Is the API protected by HTTPS?
"templates": { # Templates sample
"basic": { # Template name
Expand All @@ -22,5 +23,5 @@
},
"EAUTH": "pam", # The configured external_auth system
"FLAVOUR": "rest_cherrypy", # The netapi implementation configured on salt-master
"PATH_PREFIX": "/", # The prefix of saltpad url
"PATH_PREFIX": "/" # The prefix of saltpad url
}
22 changes: 11 additions & 11 deletions webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ module.exports = {
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
],
resolve: {
extensions: ['', '.js', '.jsx', '.css'],
extensions: ['*', '.js', '.jsx', '.css'],
// Tell webpack to look for required files in bower and node
modulesDirectories: ['bower_components', 'node_modules']
modules: ['bower_components', 'node_modules']
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
loader: 'babel-loader',
include: path.join(__dirname, 'app'),
query: {
optional: ['runtime'],
Expand All @@ -48,13 +48,13 @@ module.exports = {
{
test: /\.css$/, loader: "style-loader!css-loader"
},
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&minetype=application/font-woff" },
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&minetype=application/font-woff" },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&minetype=application/octet-stream" },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&minetype=image/svg+xml" },
{ test: /\.jpg$/, loader: "file" },
{ test: /\.png$/, loader: "file" },
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&minetype=application/font-woff" },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&minetype=application/octet-stream" },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader" },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&minetype=image/svg+xml" },
{ test: /\.jpg$/, loader: "file-loader" },
{ test: /\.png$/, loader: "file-loader" },
]
}
}
34 changes: 21 additions & 13 deletions webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
filename: "/static/[name].js"
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
// new webpack.DefinePlugin({
// 'process.env': {
// 'NODE_ENV': JSON.stringify('production')
Expand All @@ -33,27 +33,35 @@ module.exports = {
new ExtractTextPlugin("/static/styles.css"),
],
resolve: {
extensions: ['', '.js', '.jsx'],
extensions: ['*', '.js', '.jsx'],
// Tell webpack to look for required files in bower and node
modulesDirectories: ['bower_components', 'node_modules']
modules: ['bower_components', 'node_modules']
},
module: {
loaders: [
{
test: /\.jsx?$/,
loaders: ['babel?optional[]=runtime&stage=0'],
loaders: ['babel-loader?optional[]=runtime&stage=0'],
include: path.join(__dirname, 'app')
},
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?name=/static/[name]-[hash].[ext]" },
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?name=/static/[name]-[hash].[ext]" },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?name=/static/[name]-[hash].[ext]" },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?name=/static/[name]-[hash].[ext]" },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?name=/static/[name]-[hash].[ext]" },
{ test: /\.jpg$/, loader: "file-loader?name=[name]-[hash].[ext]" },
{ test: /\.png$/, loader: "file-loader?name=[name]-[hash].[ext]" },
{
test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader")
},
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "file?name=/static/[name]-[hash].[ext]" },
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "file?name=/static/[name]-[hash].[ext]" },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "file?name=/static/[name]-[hash].[ext]" },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file?name=/static/[name]-[hash].[ext]" },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "file?name=/static/[name]-[hash].[ext]" },
{ test: /\.jpg$/, loader: "file?name=[name]-[hash].[ext]" },
{ test: /\.png$/, loader: "file?name=[name]-[hash].[ext]" },
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
}
]
}
]
}
};