Skip to content

Commit

Permalink
workaround for devserver proxy to replace header 'origin' with target…
Browse files Browse the repository at this point in the history
… host

Signed-off-by: Oleksii Kurinnyi <[email protected]>
  • Loading branch information
akurinnoy committed Aug 23, 2019
1 parent 3b14f91 commit a6ebc9c
Showing 1 changed file with 50 additions and 38 deletions.
88 changes: 50 additions & 38 deletions workspace-loader/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,60 @@
* Red Hat, Inc. - initial API and implementation
*******************************************************************************/

const path = require('path');
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = merge(common, {
mode: 'development',
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.css$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}]
}
]
},
devServer: {
contentBase: './dist',
port: 3000,
index: 'index.html',
historyApiFallback: true,
proxy: {
'/api/websocket': {
target: 'http://localhost:8080',
ws: true,
changeOrigin: true
module.exports = env => {
const proxyTarget = env && env.target ? env.target : 'http://localhost:8080';

return merge(
common,
{
mode: 'development',
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.css$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}]
}
]
},
'/api': {
target: 'http://localhost:8080',
changeOrigin: true
devServer: {
contentBase: path.resolve(__dirname, './target/dist'),
host: 'localhost',
port: 3000,
index: 'index.html',
historyApiFallback: true,
proxy: {
'/api/websocket': {
target: proxyTarget,
ws: true,
changeOrigin: true
},
'/api': {
target: proxyTarget,
changeOrigin: true,
headers: {
origin: proxyTarget
}
},
}
},
plugins: [
new HtmlWebpackPlugin({
inject: false,
title: "Che Workspace Loader",
template: "src/index.html",
urlPrefix: "/"
})
]
}
},
plugins: [
new HtmlWebpackPlugin({
inject: false,
title: "Che Workspace Loader",
template: "src/index.html",
urlPrefix: "/"
})
]
});
)
};

0 comments on commit a6ebc9c

Please sign in to comment.