Skip to content

Commit b0e7eb0

Browse files
committed
feat: Add Flag to disable PREP
PREP can be disabled when the server is started with the `--no-prep` flag.
1 parent bda034a commit b0e7eb0

File tree

10 files changed

+45
-21
lines changed

10 files changed

+45
-21
lines changed

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Your users will have a dedicated folder under `./data` at `./data/<username>.<yo
138138
> To use Gmail you may need to configure ["Allow Less Secure Apps"](https://www.google.com/settings/security/lesssecureapps) in your Gmail account unless you are using 2FA in which case you would have to create an [Application Specific](https://security.google.com/settings/security/apppasswords) password. You also may need to unlock your account with ["Allow access to your Google account"](https://accounts.google.com/DisplayUnlockCaptcha) to use SMTP.
139139
140140
also add to `config.json`
141-
```
141+
```
142142
"useEmail": true,
143143
"emailHost": "smtp.gmail.com",
144144
"emailPort": "465",
@@ -206,6 +206,7 @@ $ solid start --help
206206
--multiuser Enable multi-user mode
207207
--idp [value] Obsolete; use --multiuser
208208
--no-live Disable live support through WebSockets
209+
--no-prep Disable Per Resource Events
209210
--proxy [value] Obsolete; use --corsProxy
210211
--cors-proxy [value] Serve the CORS proxy on this path
211212
--suppress-data-browser Suppress provision of a data browser
@@ -271,7 +272,7 @@ docker run -p 8443:8443 --name solid node-solid-server
271272

272273

273274
This will enable you to login to solid on https://localhost:8443 and then create a new account
274-
but not yet use that account. After a new account is made you will need to create an entry for
275+
but not yet use that account. After a new account is made you will need to create an entry for
275276
it in your local (/etc/)hosts file in line with the account and subdomain, i.e. --
276277

277278
```pre
@@ -280,16 +281,16 @@ it in your local (/etc/)hosts file in line with the account and subdomain, i.e.
280281

281282
You can modify the config within the docker container as follows:
282283

283-
- Copy the `config.json` to the current directory with:
284+
- Copy the `config.json` to the current directory with:
284285
```bash
285286
docker cp solid:/usr/src/app/config.json .
286287
```
287288
- Edit the `config.json` file
288-
- Copy the file back with
289+
- Copy the file back with
289290
```bash
290291
docker cp config.json solid:/usr/src/app/
291292
```
292-
- Restart the server with
293+
- Restart the server with
293294
```bash
294295
docker restart solid
295296
```

bin/lib/options.js

+6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ module.exports = [
143143
flag: true,
144144
default: false
145145
},
146+
{
147+
name: 'no-prep',
148+
help: 'Disable Per Resource Events',
149+
flag: true,
150+
default: false
151+
},
146152
// {
147153
// full: 'default-app',
148154
// help: 'URI to use as a default app for resources (default: https://linkeddata.github.io/warp/#/list/)'

lib/create-app.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ function createApp (argv = {}) {
6767
const app = express()
6868

6969
// Add PREP support
70-
app.use(acceptEvents, events, eventID, prep)
70+
if (argv.prep) {
71+
app.use(eventID)
72+
app.use(acceptEvents, events, prep)
73+
}
7174

7275
initAppLocals(app, argv, ldp)
7376
initHeaders(app)
@@ -123,7 +126,7 @@ function createApp (argv = {}) {
123126
}
124127

125128
// Attach the LDP middleware
126-
app.use('/', LdpMiddleware(corsSettings))
129+
app.use('/', LdpMiddleware(corsSettings, argv.prep))
127130

128131
// https://stackoverflow.com/questions/51741383/nodejs-express-return-405-for-un-supported-method
129132
app.use(function (req, res, next) {
@@ -176,6 +179,7 @@ function initAppLocals (app, argv, ldp) {
176179
app.locals.enforceToc = argv.enforceToc
177180
app.locals.tocUri = argv.tocUri
178181
app.locals.disablePasswordChecks = argv.disablePasswordChecks
182+
app.locals.prep = argv.prep
179183

180184
if (argv.email && argv.email.host) {
181185
app.locals.emailService = new EmailService(argv.templates.email, argv.email)
@@ -295,7 +299,7 @@ function initWebId (argv, app, ldp) {
295299
initAuthentication(app, argv)
296300

297301
if (argv.multiuser) {
298-
app.use(vhost('*', LdpMiddleware(corsSettings)))
302+
app.use(vhost('*', LdpMiddleware(corsSettings, argv.prep)))
299303
}
300304
}
301305

lib/handlers/delete.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ async function handler (req, res, next) {
66
debug('DELETE -- Request on' + req.originalUrl)
77

88
const ldp = req.app.locals.ldp
9+
const prep = req.app.locals.prep
910
try {
1011
await ldp.delete(req)
1112
debug('DELETE -- Ok.')
1213
// Add event-id for notifications
13-
res.setHeader('Event-ID', res.setEventID())
14+
prep && res.setHeader('Event-ID', res.setEventID())
1415
res.sendStatus(200)
1516
next()
1617
} catch (err) {

lib/handlers/get.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const prepConfig = 'accept=("message/rfc822" "application/ld+json" "text/turtle"
2323

2424
async function handler (req, res, next) {
2525
const ldp = req.app.locals.ldp
26+
const prep = req.app.locals.prep
2627
const includeBody = req.method === 'GET'
2728
const negotiator = new Negotiator(req)
2829
const baseUri = ldp.resourceMapper.resolveUrl(req.hostname, req.path)
@@ -138,7 +139,7 @@ async function handler (req, res, next) {
138139
res.statusCode = 206
139140
}
140141

141-
if (isRdf(contentType) && !res.sendEvents({
142+
if (prep & isRdf(contentType) && !res.sendEvents({
142143
config: { prep: prepConfig },
143144
body: stream,
144145
isBodyStream: true,
@@ -160,7 +161,7 @@ async function handler (req, res, next) {
160161
const headers = {
161162
'Content-Type': possibleRDFType
162163
}
163-
if (isRdf(contentType) && !res.sendEvents({
164+
if (prep && isRdf(contentType) && !res.sendEvents({
164165
config: { prep: prepConfig },
165166
body: data,
166167
headers

lib/handlers/patch.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function contentForNew (contentType) {
3939
// Handles a PATCH request
4040
async function patchHandler (req, res, next) {
4141
debug(`PATCH -- ${req.originalUrl}`)
42+
const prep = req.app.locals.prep
4243
try {
4344
// Obtain details of the target resource
4445
const ldp = req.app.locals.ldp
@@ -92,7 +93,7 @@ async function patchHandler (req, res, next) {
9293
})
9394

9495
// Add event-id for notifications
95-
res.setHeader('Event-ID', res.setEventID())
96+
prep && res.setHeader('Event-ID', res.setEventID())
9697
// Send the status and result to the client
9798
res.status(resourceExists ? 200 : 201)
9899
res.send(result)

lib/handlers/post.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const getContentType = require('../utils').getContentType
1111

1212
async function handler (req, res, next) {
1313
const ldp = req.app.locals.ldp
14+
const prep = req.app.locals.prep
1415
const contentType = getContentType(req.headers)
1516
debug('content-type is ', contentType)
1617
// Handle SPARQL(-update?) query
@@ -73,7 +74,7 @@ async function handler (req, res, next) {
7374
busboy.on('finish', function () {
7475
debug('Done storing files')
7576
// Add event-id for notifications
76-
res.setHeader('Event-ID', res.setEventID())
77+
prep && res.setHeader('Event-ID', res.setEventID())
7778
res.sendStatus(200)
7879
next()
7980
})
@@ -94,7 +95,7 @@ async function handler (req, res, next) {
9495
header.addLinks(res, links)
9596
res.set('Location', resourcePath)
9697
// Add event-id for notifications
97-
res.setHeader('Event-ID', res.setEventID())
98+
prep && res.setHeader('Event-ID', res.setEventID())
9899
res.sendStatus(201)
99100
next()
100101
},

lib/handlers/put.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ async function checkPermission (request, resourceExists) {
5959
// TODO could be renamed as putResource (it now covers container and non-container)
6060
async function putStream (req, res, next, stream = req) {
6161
const ldp = req.app.locals.ldp
62+
const prep = req.app.locals.prep
6263
// try {
6364
// Obtain details of the target resource
6465
let resourceExists = true
@@ -78,7 +79,7 @@ async function putStream (req, res, next, stream = req) {
7879
if (!req.originalUrl.endsWith('.acl')) await checkPermission(req, resourceExists)
7980
await ldp.put(req, stream, getContentType(req.headers))
8081
// Add event-id for notifications
81-
res.setHeader('Event-ID', res.setEventID())
82+
prep && res.setHeader('Event-ID', res.setEventID())
8283
res.sendStatus(resourceExists ? 204 : 201)
8384
return next()
8485
} catch (err) {

lib/ldp-middleware.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const index = require('./handlers/index')
1212
const copy = require('./handlers/copy')
1313
const notify = require('./handlers/notify')
1414

15-
function LdpMiddleware (corsSettings) {
15+
function LdpMiddleware (corsSettings, prep) {
1616
const router = express.Router('/')
1717

1818
// Add Link headers
@@ -24,10 +24,17 @@ function LdpMiddleware (corsSettings) {
2424

2525
router.copy('/*', allow('Write'), copy)
2626
router.get('/*', index, allow('Read'), header.addPermissions, get)
27-
router.post('/*', allow('Append'), post, notify)
28-
router.patch('/*', allow('Append'), patch, notify)
29-
router.put('/*', allow('Append'), put, notify)
30-
router.delete('/*', allow('Write'), del, notify)
27+
router.post('/*', allow('Append'), post)
28+
router.patch('/*', allow('Append'), patch)
29+
router.put('/*', allow('Append'), put)
30+
router.delete('/*', allow('Write'), del)
31+
32+
if (prep) {
33+
router.post('/*', notify)
34+
router.patch('/*', notify)
35+
router.put('/*', notify)
36+
router.delete('/*', notify)
37+
}
3138

3239
return router
3340
}

test/integration/prep-test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ describe('Per Resource Events Protocol', function () {
1717
dataBrowserPath: 'default',
1818
root: path.join(__dirname, '../resources'),
1919
auth: 'oidc',
20-
webid: false
20+
webid: false,
21+
prep: true
2122
})
2223
server.listen(8443, done)
2324
})

0 commit comments

Comments
 (0)