1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
const express = require('express');
const path = require('path');
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
const config = require("./config/webpack.dev-server.config.json");
module.exports = merge(common, {
mode: 'development',
devtool: 'inline-source-map',
target: 'web',
devServer: {
// contentBase: path.join(__dirname, './public/assets'),
publicPath: `${config.protocol}://${config.host}:${config.port}/${path.basename(__dirname)}`,
compress: true,
port: config.port,
historyApiFallback: true,
https: config.protocol === 'https',
headers: {
'Access-Control-Allow-Origin': '*'
},
// Serve static files with appropriate headers
before: (app, server) => {
['flash', 'fonts', 'images', 'sounds'].forEach(type => {
app.use(
`/${path.basename(__dirname)}/${type}/`,
express.static(path.join(__dirname, `./public/assets/${type}/`), {
setHeaders: (res, path) => {
res.set('Access-Control-Allow-Origin', '*');
}
})
);
});
['ckeditor', 'mathjax'].forEach(vendor => {
app.use(
`/${path.basename(__dirname)}/javascripts/${vendor}`,
express.static(path.join(__dirname, `./public/assets/javascripts/${vendor}/`), {
setHeaders: (res, path) => {
res.set('Access-Control-Allow-Origin', '*');
}
})
);
});
}
}
});
|