forked from DO-SAY-GO/dn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibraryServer.js
More file actions
39 lines (30 loc) · 815 Bytes
/
libraryServer.js
File metadata and controls
39 lines (30 loc) · 815 Bytes
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
import fs from 'fs';
import path from 'path';
import express from 'express';
import serveIndex from 'serve-index';
import args from './args.js';
import {say} from './common.js';
const SITE_PATH = path.join(__dirname, 'public');
const libraryPath = args.libraryPath || path.join(__dirname, 'public', 'library');
const app = express();
let upAt;
const LibraryServer = {
start
}
export default LibraryServer;
async function start({server_port}) {
addHandlers();
app.listen(Number(server_port), err => {
if ( err ) {
throw err;
}
upAt = new Date;
say({server_up:{upAt,server_port}});
});
}
function addHandlers() {
app.use(express.static(SITE_PATH));
if ( !! libraryPath ) {
app.use("/library", express.static(libraryPath), serveIndex(libraryPath, {icons:true}));
}
}