Skip to content

Commit 89fe55e

Browse files
Add --config-path parameter (for default templates and apps)
1 parent 6614f23 commit 89fe55e

File tree

5 files changed

+41
-24
lines changed

5 files changed

+41
-24
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ profile
1010
inbox
1111
.acl
1212
config.json
13+
config/templates
14+
config/apps
1315
settings
1416
.db/
1517
.nyc_output

bin/lib/options.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ module.exports = [
4646
default: '/',
4747
prompt: true
4848
},
49+
{
50+
name: 'config-path',
51+
question: 'Path to the config directory (for example: /etc/solid-server)',
52+
default: './config',
53+
prompt: true
54+
},
4955
{
5056
name: 'db-path',
5157
question: 'Path to the server metadata db directory (for users/apps etc)',

config/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module.exports = {
44
'auth': 'tls',
5+
'configPath': './config',
56
'dbPath': './.db',
67
'port': 8443,
78
'serverUri': 'https://localhost:8443',

lib/create-app.js

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ const corsSettings = cors({
3535
})
3636

3737
function createApp (argv = {}) {
38+
// Override default configs (defaults) with passed-in params (argv)
3839
argv = Object.assign({}, defaults, argv)
3940

4041
argv.host = SolidHost.from({ port: argv.port, serverUri: argv.serverUri })
4142

42-
argv.templates = initTemplates()
43+
let configPath = initConfigPath(argv)
44+
45+
argv.templates = initTemplateDirs(configPath)
4346

4447
let ldp = new LDP(argv)
4548
let app = express()
@@ -103,15 +106,22 @@ function createApp (argv = {}) {
103106
return app
104107
}
105108

106-
function initTemplates () {
107-
let accountTemplatePath = ensureTemplateCopiedTo(
108-
'../default-templates/new-account',
109-
'../config/account-template'
109+
function initConfigPath (argv) {
110+
let configPath = path.resolve(argv.configPath)
111+
fs.mkdirp(configPath)
112+
113+
return configPath
114+
}
115+
116+
function initTemplateDirs (configPath) {
117+
let accountTemplatePath = ensureDirCopy(
118+
'./default-templates/new-account',
119+
path.join(configPath, 'templates', 'new-account')
110120
)
111121

112-
let emailTemplatesPath = ensureTemplateCopiedTo(
113-
'../default-templates/emails',
114-
'../config/email-templates'
122+
let emailTemplatesPath = ensureDirCopy(
123+
'./default-templates/emails',
124+
path.join(configPath, 'templates', 'emails')
115125
)
116126

117127
return {
@@ -121,29 +131,25 @@ function initTemplates () {
121131
}
122132

123133
/**
124-
* Ensures that a template directory has been initialized in `config/` from
125-
* default templates.
134+
* Ensures that a directory has been copied / initialized. Used to ensure that
135+
* account templates, email templates and default apps have been copied from
136+
* their defaults to the customizable config directory, at server startup.
126137
*
127-
* @param defaultTemplateDir {string} Path to a default template directory,
128-
* relative to `lib/`. For example, '../default-templates/emails' contains
129-
* various email templates pre-defined by the Solid dev team.
138+
* @param fromDir {string} Path to copy from (defaults)
130139
*
131-
* @param configTemplateDir {string} Path to a template directory customized
132-
* to this particular installation (relative to `lib/`). Server operators
133-
* are encouraged to override/customize these templates in the `config/`
134-
* directory.
140+
* @param toDir {string} Path to copy to (customizable config)
135141
*
136-
* @return {string} Returns the absolute path to the customizable template copy
142+
* @return {string} Returns the absolute path for `toDir`
137143
*/
138-
function ensureTemplateCopiedTo (defaultTemplateDir, configTemplateDir) {
139-
let configTemplatePath = path.join(__dirname, configTemplateDir)
140-
let defaultTemplatePath = path.join(__dirname, defaultTemplateDir)
144+
function ensureDirCopy (fromDir, toDir) {
145+
fromDir = path.resolve(fromDir)
146+
toDir = path.resolve(toDir)
141147

142-
if (!fs.existsSync(configTemplatePath)) {
143-
fs.copySync(defaultTemplatePath, configTemplatePath)
148+
if (!fs.existsSync(toDir)) {
149+
fs.copySync(fromDir, toDir)
144150
}
145151

146-
return configTemplatePath
152+
return toDir
147153
}
148154

149155
/**

lib/ldp.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class LDP {
8484
}
8585

8686
debug.settings('Auth method: ' + this.auth)
87+
debug.settings('Db path: ' + this.dbPath)
88+
debug.settings('Config path: ' + this.configPath)
8789
debug.settings('Suffix Acl: ' + this.suffixAcl)
8890
debug.settings('Suffix Meta: ' + this.suffixMeta)
8991
debug.settings('Filesystem Root: ' + this.root)

0 commit comments

Comments
 (0)