Skip to content

Instantly share code, notes, and snippets.

@wldcordeiro
Created June 23, 2018 17:09
Show Gist options
  • Save wldcordeiro/5cb8860b7285a0996f8d79840e4fa046 to your computer and use it in GitHub Desktop.
Save wldcordeiro/5cb8860b7285a0996f8d79840e4fa046 to your computer and use it in GitHub Desktop.
const merge = require('webpack-merge')
const convert = require('koa-connect')
const history = require('connect-history-api-fallback')
const proxy = require('http-proxy-middleware')
const common = require('./webpack.common.js')
const config = require('./env.config')
const { AUTHM_GATEWAY_URL, DAM_ROOT_PATH } = config
const rewriteRegex = new RegExp(`^${DAM_ROOT_PATH}/.`)
const proxiedPaths = [
'/authorize',
'/auth',
'/token',
'/oauth',
'/requests',
'/request',
'/static',
'/messages',
'/javascript',
'/attask',
'/tile',
'/user',
].concat(
Object.keys(config)
.map(k => config[k])
.filter(
s =>
typeof s === 'string' &&
s !== DAM_ROOT_PATH &&
s.startsWith(DAM_ROOT_PATH)
)
)
module.exports = merge(common, {
mode: 'development',
devtool: 'inline-source-map',
module: {
rules: [{ test: /\.css$/, use: ['style-loader', 'css-loader'] }],
},
serve: {
port: 3000,
content: 'public',
dev: {
publicPath: DAM_ROOT_PATH,
},
add: app => {
app.use(
convert(
proxy(proxiedPaths, {
target: AUTHM_GATEWAY_URL,
secure: false,
changeOrigin: true,
cookieDomainRewrite: { '*': '' },
})
)
)
app.use(
convert(
history({
rewrites: [
{ from: rewriteRegex, to: `${DAM_ROOT_PATH}/index.html` },
],
})
)
)
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment