-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (27 loc) · 1.26 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
const express = require('express');
const fs = require('fs');
const config = require('./config.js');
let authenticator = require('./authenticator.js');
let archiver = require('./archiver.js');
function main () {
let app = express();
// routes
app.post('/login', authenticator.login);
app.get('/archive/:directoryName/directory', authenticator.checkToken, archiver.getArchiveDirectoryCollectionService);
app.post('/archive/update-directory-cache', authenticator.checkToken, archiver.updateArchiveDirectoryCacheService);
app.get('/archive/:directoryName/file', authenticator.checkToken, archiver.getArchiveFileCollectionService);
app.put('/queue/:fileName', authenticator.checkToken, archiver.putQueueFileService);
app.get('/queue', authenticator.checkToken, archiver.getQueueFileCollectionService);
app.get('/config/:parameterName', authenticator.checkToken, archiver.getConfigParameterService);
app.put('/config/:parameterName', authenticator.checkToken, archiver.putConfigParameterService);
// embed frontend
app.use(express.static('public'));
// error handler
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send(err.message)
});
// startup
app.listen(config.port, () => console.log(`App listening at port ${config.port}`));
}
main();