aboutsummaryrefslogtreecommitdiff
path: root/src/app.mjs
blob: 7d45d40b5da678e7cc75f645cc279ab73c4c5351 (plain)
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
'use-strict';

const fs = require('fs');
const express = require('express');
const mustache = require('mustache-express');
const path = require('path');

const app = express();

app.engine('html', mustache());
app.set('view engine', 'html');
app.set('views',path.join(__dirname, 'views'));

app.use('/default', express.static('default'));
app.use(express.static('static'));

app.get('/', (req, res) => {

  const listFile = fs.readdirSync("./default");
  const options = listFile.map( file => {
    const text = file.replace('.json', '');
    return `<option value="${file}">${text}</option>`;
  });
  console.log(options);
    res.render('index', {listFile: options.join('')});
});

const server = app.listen(8095, () => {
  const host = server.address().address;
  const port = server.address().port;
  console.log(`[${new Date()}] > App listening at http://%s:%s`, host, port);
});