Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions lib/api/authn/webid-oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

const express = require('express')
const { routeResolvedFile } = require('../../utils')
const bodyParser = require('body-parser').urlencoded({ extended: false })
const OidcManager = require('../../models/oidc-manager')
const { LoginRequest } = require('../../requests/login-request')
Expand Down Expand Up @@ -182,15 +183,6 @@ function isEmptyToken (req) {
return false
}

/**
* Adds a route that serves a static file from another Node module
*/
function routeResolvedFile (router, path, file) {
const fullPath = path + file.match(/[^/]+$/)
const fullFile = require.resolve(file)
router.get(fullPath, (req, res) => res.sendFile(fullFile))
}

module.exports = {
initialize,
isEmptyToken,
Expand Down
3 changes: 3 additions & 0 deletions lib/create-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const defaults = require('../config/defaults')
const options = require('./handlers/options')
const debug = require('./debug').authentication
const path = require('path')
const { routeResolvedFile } = require('./utils')

const corsSettings = cors({
methods: [
Expand Down Expand Up @@ -53,6 +54,8 @@ function createApp (argv = {}) {

// Serve the public 'common' directory (for shared CSS files, etc)
app.use('/common', express.static(path.join(__dirname, '../common')))
routeResolvedFile(app, '/common/js/', 'mashlib/dist/mashlib.min.js')
routeResolvedFile(app, '/common/js/', 'mashlib/dist/mashlib.min.js.map')

// Add CORS proxy
if (argv.proxy) {
Expand Down
10 changes: 10 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports.reqToPath = reqToPath
module.exports.debrack = debrack
module.exports.stripLineEndings = stripLineEndings
module.exports.fullUrlForReq = fullUrlForReq
module.exports.routeResolvedFile = routeResolvedFile

const fs = require('fs')
const path = require('path')
Expand Down Expand Up @@ -229,3 +230,12 @@ function reqToPath (req) {
const root = ldp.multiuser ? ldp.root + req.hostname + '/' : ldp.root
return uriToFilename(req.path, root)
}

/**
* Adds a route that serves a static file from another Node module
*/
function routeResolvedFile (router, path, file) {
const fullPath = path + file.match(/[^/]+$/)
const fullFile = require.resolve(file)
router.get(fullPath, (req, res) => res.sendFile(fullFile))
}
Loading