Skip to content

Commit eada0d8

Browse files
Extract initErrorPages() out of LDP constructor
1 parent eef07d2 commit eada0d8

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

lib/ldp.js

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,38 +55,18 @@ class LDP {
5555
constructor (options = {}) {
5656
Object.assign(this, options)
5757

58-
// Setting root
59-
if (!this.root) {
60-
this.root = process.cwd()
61-
}
62-
if (!this.root.endsWith('/')) {
63-
this.root += '/'
64-
}
65-
66-
// Suffixes
67-
if (!this.suffixAcl) {
68-
this.suffixAcl = '.acl'
69-
}
70-
if (!this.suffixMeta) {
71-
this.suffixMeta = '.meta'
72-
}
58+
this.suffixAcl = options.suffixAcl || '.acl'
59+
this.suffixMeta = options.suffixMeta || '.meta'
7360
this.turtleExtensions = [ '.ttl', this.suffixAcl, this.suffixMeta ]
7461

75-
// Error pages folder
76-
this.errorPages = null
77-
if (!this.noErrorPages) {
78-
this.errorPages = options.errorPages
79-
if (!this.errorPages) {
80-
// TODO: For now disable error pages if errorPages parameter is not explicitly passed
81-
this.noErrorPages = true
82-
} else if (!this.errorPages.endsWith('/')) {
83-
this.errorPages += '/'
84-
}
85-
}
62+
this.root = options.root || process.cwd()
63+
if (!this.root.endsWith('/')) { this.root += '/' }
8664

87-
if (this.corsProxy && this.corsProxy[ 0 ] !== '/') {
65+
if (this.corsProxy && !this.corsProxy.startsWith('/')) {
8866
this.corsProxy = '/' + this.corsProxy
8967
}
68+
69+
this.initErrorPages(options)
9070
}
9171

9272
printDebugInfo () {
@@ -104,6 +84,19 @@ class LDP {
10484
debug.settings('Default data browser app file path: ' + this.dataBrowserPath)
10585
}
10686

87+
initErrorPages (options) {
88+
this.errorPages = null
89+
if (!this.noErrorPages) {
90+
this.errorPages = options.errorPages
91+
if (!this.errorPages) {
92+
// TODO: For now disable error pages if errorPages parameter is not explicitly passed
93+
this.noErrorPages = true
94+
} else if (!this.errorPages.endsWith('/')) {
95+
this.errorPages += '/'
96+
}
97+
}
98+
}
99+
107100
stat (file, callback) {
108101
fs.stat(file, function (err, stats) {
109102
if (err) {

0 commit comments

Comments
 (0)