-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
45 lines (43 loc) · 1.14 KB
/
index.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
const Collection = require('./lib/db')
const config = require('./lib/config')
const generateSearch = require('./lib/generate-search')
const { use, plugins } = require('./lib/plugins')
const micropubRouter = require('./lib/router')
const { addPostType } = require('./lib/post-type-discovery')
const requiredOptions = [
'siteBaseUrl',
'endpointBaseUrl',
'permalinkPattern',
'syndication',
'mediaDir',
'mediaBaseUrl',
'dbAdapter',
'dbName',
'dbPassword',
'tokenEndpoint',
]
module.exports = (options = {}) => {
try {
for (const key in options) {
if (options.hasOwnProperty(key)) {
const value = options[key]
config.set(key, value)
}
}
config.required(requiredOptions)
return {
use,
plugins,
getCollection: Collection.get,
router: micropubRouter,
generateSearch,
addPostType,
micropubEndpoint: config.get('baseUrl') + '/',
mediaEndpoint:
config.get('mediaEndpoint') || config.get('baseUrl') + '/media',
}
} catch (err) {
console.log('Micropub setup err', err)
return new Error(err)
}
}