forked from nodeSolidServer/node-solid-ws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (45 loc) · 1.43 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
46
47
48
49
var debug = require('debug')('ldnode:ws-app')
var SolidWs = require('./lib/server')
var path = require('path')
module.exports = function attachToServer (server, app, opts) {
var solidWs = new SolidWs(server, opts)
if (app) {
app.post('/*', function (req, res, next) {
debug('pub ' + req.originalUrl + ' after post')
solidWs.publish(req.originalUrl)
var parent = path.dirname(req.originalUrl) + path.sep
if (parent !== req.originalUrl) {
solidWs.publish(parent)
}
next()
})
app.patch('/*', function (req, res, next) {
debug('pub ' + req.originalUrl + ' after patch')
solidWs.publish(req.originalUrl)
var parent = path.dirname(req.originalUrl) + path.sep
if (parent !== req.originalUrl) {
solidWs.publish(parent)
}
next()
})
app.put('/*', function (req, res, next) {
debug('pub ' + req.originalUrl + ' after put')
solidWs.publish(req.originalUrl)
var parent = path.dirname(req.originalUrl) + path.sep
if (parent !== req.originalUrl) {
solidWs.publish(parent)
}
next()
})
app.delete('/*', function (req, res, next) {
debug('pub ' + req.originalUrl + ' after delete')
solidWs.publish(req.originalUrl)
var parent = path.dirname(req.originalUrl) + path.sep
if (parent !== req.originalUrl) {
solidWs.publish(parent)
}
next()
})
}
return solidWs
}