forked from jaredpalmer/razzle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrazzle.config.js
More file actions
61 lines (57 loc) · 2.12 KB
/
Copy pathrazzle.config.js
File metadata and controls
61 lines (57 loc) · 2.12 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
const devcert = require('devcert');
const cors = require('cors');
const whitelist = ['https://localhost:3000', 'https://localhost:3001']; //white list consumers
const corsOptions = {
origin: '*',
// function (origin, callback) {
// console.log(origin);
// if (whitelist.indexOf(origin) !== -1) {
// callback(null, true);
// } else {
// callback(null, false);
// }
// },
methods: ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS'],
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
credentials: true, //Credentials are cookies, authorization headers or TLS client certificates.
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With', 'device-remember-token', 'Access-Control-Allow-Origin', 'Origin', 'Accept']
};
module.exports = {
modifyOptions(opts) { // use modifyOptions so certificateFor is called once
const options = opts.options.razzleOptions;
return new Promise(async (resolve) => {
const httpsCredentials = await devcert.certificateFor('localhost');
const stringHttpsCredentials = {
key: httpsCredentials.key.toString(),
cert: httpsCredentials.cert.toString()
};
options.HTTPS_CREDENTIALS = stringHttpsCredentials;
resolve(options);
});
},
modifyWebpackOptions(opts) {
const razzleOptions = opts.options.razzleOptions;
const webpackOptions = opts.options.webpackOptions;
if (opts.env.target === 'node' && opts.env.dev) {
webpackOptions.definePluginOptions.HTTPS_CREDENTIALS = JSON.stringify(razzleOptions.HTTPS_CREDENTIALS);
}
return webpackOptions;
},
modifyWebpackConfig(opts) {
const config = opts.webpackConfig;
const options = opts.options.razzleOptions;
if (opts.env.target === 'web' && opts.env.dev) {
config.devServer.https = options.HTTPS_CREDENTIALS;
// config.devServer.before = function (app, server, compiler) {
// app.use(cors('*')); console.log('web');
//
// }
config.devServer.headers = {
"Access-Control-Allow-Origin": "*",
https: true
}
}
return config;
},
};