-
Notifications
You must be signed in to change notification settings - Fork 17
/
migrateV1Config.js
79 lines (71 loc) · 2.13 KB
/
migrateV1Config.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var yaml = require('js-yaml');
/* This is sample preprocessor, modify it for your needs */
module.exports = function(argv, data, cb) {
var oldWarn = console.warn;
console.warn = function() {};
var config = yaml.safeLoad(data);
if(config.logging) {
if(config.logging.appLog) {
config.modules = config.modules || {};
config.modules.appLog = config.logging.appLog;
}
if(config.logging.accessLog) {
config.middleware = config.middleware || [];
config.middleware.push(
'log -> ' + config.logging.accessLog
);
}
delete config.logging;
}
config.ports = config.ports || {};
if(config.gzip) {
config.middleware = config.middleware || [];
config.middleware.push(
'gzip -> 9'
);
}
delete config.gzip;
Object.keys(config.ports).forEach(function(port) {
var portConfig = config.ports[port];
if(portConfig.gzip) {
config.ports[port] = ['gzip -> 9', portConfig];
}
delete portConfig.gzip;
portConfig.router = portConfig.router || {};
function migrateEntries(name) {
Object.keys(portConfig[name]).forEach(function(key) {
var portConfigEntry = portConfig[name][key];
if(name !== 'proxy')
portConfigEntry = name + " -> " + portConfigEntry.toString();
if(name === 'proxy' && portConfigEntry.auth) {
portConfigEntry = ['auth -> ' + portConfigEntry.auth, portConfigEntry.target];
}
portConfig.router[key] = portConfigEntry;
});
}
delete portConfig.silent;
if(portConfig.reject) {
migrateEntries('reject');
delete portConfig.reject;
}
if(portConfig.static) {
migrateEntries('static');
delete portConfig.static;
}
if(portConfig.redirect) {
migrateEntries('redirect');
delete portConfig.redirect;
}
if(portConfig.proxy) {
migrateEntries('proxy');
delete portConfig.proxy;
}
if(portConfig.ssl) { // make sure ssl is appended at the end
var sslConfig = portConfig.ssl;
delete portConfig.ssl;
portConfig.ssl = sslConfig;
}
});
console.log("Migrated old config!");
cb(null, config);
};