Skip to content
3 changes: 1 addition & 2 deletions bin/lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const options = require('./options')
const fs = require('fs')
const extend = require('extend')
const { cyan, red, bold } = require('colorette')

module.exports = function (program, server) {
Expand All @@ -23,7 +22,7 @@ module.exports = function (program, server) {
start.option('-v, --verbose', 'Print the logs to console')

start.action((opts) => {
let argv = extend({}, opts, { version: program.version() })
let argv = Object.assign({}, opts, { version: program.version() })
let configFile = argv['configFile'] || './config.json'

fs.readFile(configFile, (err, file) => {
Expand Down
4 changes: 3 additions & 1 deletion config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ module.exports = {
'port': 8443,
'serverUri': 'https://localhost:8443',
'webid': true,
'dataBrowserPath': 'default'
'dataBrowserPath': 'default',
'suffixAcl': '.acl',
'suffixMeta': '.meta'

// For use in Enterprises to configure a HTTP proxy for all outbound HTTP requests from the SOLID server (we use
// https://www.npmjs.com/package/global-tunnel-ng).
Expand Down
5 changes: 4 additions & 1 deletion lib/create-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ function createApp (argv = {}) {
// Override default configs (defaults) with passed-in params (argv)
argv = Object.assign({}, defaults, argv)

argv.host = SolidHost.from({ port: argv.port, serverUri: argv.serverUri })
const hostConfig = config.hostConfigFor(argv)
argv.host = SolidHost.from(hostConfig)

const configPath = config.initConfigDir(argv)
argv.templates = config.initTemplateDirs(configPath)

config.printDebugInfo(argv)

const ldp = new LDP(argv)

const app = express()
Expand Down
7 changes: 3 additions & 4 deletions lib/create-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function createServer (argv, app) {
argv = argv || {}
app = app || express()
const ldpApp = createApp(argv)
const ldp = ldpApp.locals.ldp || {}
let mount = argv.mount || '/'
// Removing ending '/'
if (mount.length > 1 &&
Expand Down Expand Up @@ -72,7 +71,7 @@ function createServer (argv, app) {
cert: cert
}, argv)

if (ldp.webid && ldp.auth === 'tls') {
if (argv.webid && argv.auth === 'tls') {
credentials.requestCert = true
}

Expand All @@ -98,9 +97,9 @@ function createServer (argv, app) {
}

// Setup Express app
if (ldp.live) {
if (argv.live) {
const solidWs = SolidWs(server, ldpApp)
ldpApp.locals.ldp.live = solidWs.publish.bind(solidWs)
ldpApp.locals.host.live = solidWs.publish.bind(solidWs)
}

return server
Expand Down
4 changes: 2 additions & 2 deletions lib/handlers/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const error = require('../http-error')
const RDFs = require('../ldp').RDF_MIME_TYPES

function handler (req, res, next) {
const ldp = req.app.locals.ldp
const { ldp, host: hostConfig } = req.app.locals
const includeBody = req.method === 'GET'
const negotiator = new Negotiator(req)
const baseUri = utils.getFullUri(req)
Expand All @@ -32,7 +32,7 @@ function handler (req, res, next) {
res.header('MS-Author-Via', 'SPARQL')

// Set live updates
if (ldp.live) {
if (hostConfig.live) {
res.header('Updates-Via', utils.getBaseUri(req).replace(/^http/, 'ws'))
}

Expand Down
83 changes: 40 additions & 43 deletions lib/ldp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const utils = require('./utils')
const error = require('./http-error')
const stringToStream = require('./utils').stringToStream
const serialize = require('./utils').serialize
const extend = require('extend')
const rimraf = require('rimraf')
const ldpContainer = require('./ldp-container')
const parse = require('./utils').parse
const fetch = require('node-fetch')
const { promisify } = require('util')
const defaults = require('../config/defaults')

const DEFAULT_CONTENT_TYPE = 'text/turtle'

Expand All @@ -32,61 +32,58 @@ const RDF_MIME_TYPES = [
'application/x-turtle'
]

/**
* @constructor
* @param [options={}] {Object}
* @param [options.serverUri]
* @param [options.dbPath]
* @param [options.configPath]
* @param [options.root]
* @param [options.suffixAcl]
* @param [options.suffixMeta]
* @param [options.errorPages]
* @param [options.fileBrowser]
* @param [options.suppressDataBrowser]
* @param [options.dataBrowserPath]
* @param [options.webid]
* @param [options.multiuser]
*/
class LDP {
constructor (argv = {}) {
extend(this, argv)
constructor (options = {}) {
options = Object.assign({}, defaults, options)
this.serverUri = options.serverUri
this.dbPath = options.dbPath
this.configPath = options.configPath
this.suffixAcl = options.suffixAcl
this.suffixMeta = options.suffixMeta
this.multiuser = options.multiuser
this.webid = options.webid
this.strictOrigin = options.strictOrigin
this.errorPages = options.errorPages
this.noErrorPages = options.noErrorPages
this.errorHandler = options.errorHandler
this.dataBrowserPath = options.dataBrowserPath
this.suppressDataBrowser = options.suppressDataBrowser

// Setting root
if (!this.root) {
this.root = process.cwd()
}
if (!this.root.endsWith('/')) {
this.root += '/'
}

// Suffixes
if (!this.suffixAcl) {
this.suffixAcl = '.acl'
}
if (!this.suffixMeta) {
this.suffixMeta = '.meta'
}
this.turtleExtensions = [ '.ttl', this.suffixAcl, this.suffixMeta ]

// Error pages folder
this.root = options.root || process.cwd()
if (!this.root.endsWith('/')) { this.root += '/' }

this.initErrorPages(options)
}

initErrorPages (options) {
this.errorPages = null
if (!this.noErrorPages) {
this.errorPages = argv.errorPages
this.errorPages = options.errorPages
if (!this.errorPages) {
// TODO: For now disable error pages if errorPages parameter is not explicitly passed
this.noErrorPages = true
} else if (!this.errorPages.endsWith('/')) {
this.errorPages += '/'
}
}

if (this.skin !== false) {
this.skin = true
}

if (this.corsProxy && this.corsProxy[ 0 ] !== '/') {
this.corsProxy = '/' + this.corsProxy
}

debug.settings('Server URI: ' + this.serverUri)
debug.settings('Auth method: ' + this.auth)
debug.settings('Db path: ' + this.dbPath)
debug.settings('Config path: ' + this.configPath)
debug.settings('Suffix Acl: ' + this.suffixAcl)
debug.settings('Suffix Meta: ' + this.suffixMeta)
debug.settings('Filesystem Root: ' + this.root)
debug.settings('Allow WebID authentication: ' + !!this.webid)
debug.settings('Live-updates: ' + !!this.live)
debug.settings('Multi-user: ' + !!this.multiuser)
debug.settings('Suppress default data browser app: ' + this.suppressDataBrowser)
debug.settings('Default data browser app file path: ' + this.dataBrowserPath)

return this
}

stat (file, callback) {
Expand Down
2 changes: 2 additions & 0 deletions lib/models/solid-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class SolidHost {
this.parsedUri = url.parse(this.serverUri)
this.host = this.parsedUri.host
this.hostname = this.parsedUri.hostname

this.live = options.live
}

/**
Expand Down
28 changes: 27 additions & 1 deletion lib/server-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@

const fs = require('fs-extra')
const path = require('path')
const debug = require('./debug')

function printDebugInfo (options) {
debug.settings('Server URI: ' + options.serverUri)
debug.settings('Auth method: ' + options.auth)
debug.settings('Db path: ' + options.dbPath)
debug.settings('Config path: ' + options.configPath)
debug.settings('Suffix Acl: ' + options.suffixAcl)
debug.settings('Suffix Meta: ' + options.suffixMeta)
debug.settings('Filesystem Root: ' + options.root)
debug.settings('Allow WebID authentication: ' + !!options.webid)
debug.settings('Live-updates: ' + !!options.live)
debug.settings('Multi-user: ' + !!options.multiuser)
debug.settings('Suppress default data browser app: ' + options.suppressDataBrowser)
debug.settings('Default data browser app file path: ' + options.dataBrowserPath)
}

function hostConfigFor (argv) {
return {
port: argv.port,
serverUri: argv.serverUri,
live: argv.live
}
}

/**
* Ensures that a directory has been copied / initialized. Used to ensure that
Expand Down Expand Up @@ -130,7 +154,9 @@ function initTemplateDirs (configPath) {
module.exports = {
ensureDirCopyExists,
ensureWelcomePage,
hostConfigFor,
initConfigDir,
initDefaultViews,
initTemplateDirs
initTemplateDirs,
printDebugInfo
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"express": "^4.16.3",
"express-handlebars": "^3.0.0",
"express-session": "^1.15.6",
"extend": "^3.0.0",
"from2": "^2.1.0",
"fs-extra": "^2.1.0",
"glob": "^7.1.1",
Expand Down