| 11 | import notify from './handlers/notify.mjs' |
| 12 | |
| 13 | export default function LdpMiddleware (corsSettings, prep) { |
| 14 | const router = express.Router('/') |
| 15 | |
| 16 | // Add Link headers |
| 17 | router.use(linksHandler) |
| 18 | |
| 19 | if (corsSettings) { |
| 20 | router.use(corsSettings) |
| 21 | } |
| 22 | |
| 23 | router.copy('/*', allow('Write'), copy) |
| 24 | router.get('/*', index, allow('Read'), addPermissions, get) |
| 25 | router.post('/*', allow('Append'), post) |
| 26 | router.patch('/*', allow('Append'), patch) |
| 27 | router.put('/*', allow('Append'), put) |
| 28 | router.delete('/*', allow('Write'), del) |
| 29 | |
| 30 | if (prep) { |
| 31 | router.post('/*', notify) |
| 32 | router.patch('/*', notify) |
| 33 | router.put('/*', notify) |
| 34 | router.delete('/*', notify) |
| 35 | } |
| 36 | |
| 37 | return router |
| 38 | } |