-
Notifications
You must be signed in to change notification settings - Fork 665
Expand file tree
/
Copy pathcreate-config
More file actions
executable file
·112 lines (100 loc) · 2.57 KB
/
Copy pathcreate-config
File metadata and controls
executable file
·112 lines (100 loc) · 2.57 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env node
// Ghost Configuration for Heroku
const fs = require('fs');
const path = require('path');
const url = require('url');
const envValues = require('./common/env-values');
const appRoot = path.join(__dirname, '..');
const getMysqlConfig = connectionUrl => {
if (connectionUrl === null) {
return {};
}
const dbConfig = url.parse(connectionUrl);
if (dbConfig === null) {
return {};
}
const dbAuth = dbConfig.auth ? dbConfig.auth.split(':') : [];
const dbUser = dbAuth[0];
const dbPassword = dbAuth[1];
let dbName;
if (dbConfig.pathname === null) {
dbName = 'ghost';
} else {
dbName = dbConfig.pathname.split('/')[1];
}
const dbConnection = {
host: dbConfig.hostname,
port: dbConfig.port || '3306',
user: dbUser,
password: dbPassword,
database: dbName
};
return dbConnection;
};
const createConfig = () => {
let fileStorage;
let storage;
if (!!process.env.S3_ACCESS_KEY_ID) {
fileStorage = true;
storage = {
active: 's3',
s3: {
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_ACCESS_SECRET_KEY,
bucket: process.env.S3_BUCKET_NAME,
region: process.env.S3_BUCKET_REGION,
assetHost: process.env.S3_ASSET_HOST_URL
}
};
} else if (!!process.env.BUCKETEER_AWS_ACCESS_KEY_ID) {
fileStorage = true;
storage = {
active: 's3',
s3: {
accessKeyId: process.env.BUCKETEER_AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.BUCKETEER_AWS_SECRET_ACCESS_KEY,
bucket: process.env.BUCKETEER_BUCKET_NAME,
region: process.env.S3_BUCKET_REGION,
assetHost: process.env.S3_ASSET_HOST_URL
}
};
} else {
fileStorage = false;
storage = {};
}
config = {
url: process.env.PUBLIC_URL,
logging: {
level: 'info',
transports: ['stdout']
},
mail: {
transport: 'SMTP',
options: {
service: 'Mailgun',
auth: {
user: process.env.MAILGUN_SMTP_LOGIN,
pass: process.env.MAILGUN_SMTP_PASSWORD
}
}
},
fileStorage,
storage,
database: {
client: 'mysql',
connection: getMysqlConfig(envValues.mysqlDatabaseUrl),
pool: { min: 0, max: 5 },
debug: false
},
server: {
host: '0.0.0.0',
port: process.env.PORT
},
paths: {
contentPath: path.join(appRoot, '/content/')
}
};
return config;
};
const configContents = JSON.stringify(createConfig(), null, 2);
fs.writeFileSync(path.join(appRoot, 'config.production.json'), configContents);