forked from agents-lp/agents-lp.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
28 lines (21 loc) · 765 Bytes
/
server.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
const express = require('express');
const app = express();
const port = 3123;
const { lstatSync, readdirSync } = require('fs')
const { join } = require('path')
const isDirectory = source => lstatSync(source).isDirectory()
const getDirectories = source =>
readdirSync(source).map(name => join(source, name)).filter(isDirectory)
const dirs = getDirectories('.');
const dirsToExclude = ['.git', 'node_modules'];
const dirLinks = [];
dirs.forEach((dir => {
if (dirsToExclude.indexOf(dir) == -1) {
dirLinks.push(`<div><a href="/${dir}">${dir}</a></div>`);
}
}));
app.use(express.static('.'));
app.get('/', function (req, res) {
res.send(dirLinks.join(''));
});
app.listen(port, () => console.log(`server is available under http://localhost:${port}`));