-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·41 lines (32 loc) · 1.08 KB
/
app.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
const Express = require('express');
const fs = require('fs');
const path = require('path');
const Entry = require('./entry');
require('dotenv').config();
const app = new Express();
app.use('/materialize', Express.static(path.join(__dirname,
'node_modules',
'materialize-css',
'dist')));
app.use('/media', Express.static(path.join(__dirname, 'media')));
app.use('/static', Express.static(path.join(__dirname, 'static')));
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
let query = req.query.dir;
if (!query) query = '';
const url = path.join(process.env.BASEPATH, query);
const files = [];
fs.readdir(url, async (err, filedata) => {
for (const file of filedata) {
if (fs.lstatSync(path.join(url, file)).isDirectory()) {
files.push(new Entry(file, `?dir=${query}/${file}`, 'directory'));
continue;
}
files.push(new Entry(file, path.join(url, file)));
}
return res.render('index', {files});
});
});
app.listen(process.env.PORT, () => {
console.log(`Server located at http://localhost:${process.env.PORT}`);
});