-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (59 loc) · 1.68 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import express from 'express';
import path from 'path';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// @ts-ignore
//const { __dirname } = fileDirName();
const app = express();
const BASE_DIR = path.join(__dirname, 'src');
const HTML_DIR = path.join(BASE_DIR, 'html');
const port = 3000;
//console.log({ BASE_DIR, HTML_DIR });
const router = express.Router();
app.use((_, res, next) => {
let now = new Date();
console.log('Time: ', now.toUTCString());
next();
});
router.get('/', (_, res) => {
res.sendFile(`${HTML_DIR}/index.html`);
});
router.get('/index', (_, res) => {
res.sendFile(`${HTML_DIR}/index.html`);
});
router.get('/css', (_, res) => {
res.sendFile(`${HTML_DIR}/css1-color.html`);
});
router.get('/named', (_, res) => {
res.sendFile(`${HTML_DIR}/named-color.html`);
});
router.get('/mix', (_, res) => {
res.sendFile(`${HTML_DIR}/color-mix.html`);
});
router.get('/wall', (_, res) => {
res.sendFile(`${HTML_DIR}/color-wall.html`);
});
router.get('/space', (_, res) => {
res.sendFile(`${HTML_DIR}/color-space.html`);
});
router.get('/relative', (_, res) => {
res.sendFile(`${HTML_DIR}/relative-color.html`);
});
router.get('/syntax', (_, res) => {
res.sendFile(`${HTML_DIR}/color-syntax.html`);
});
router.get('/hsl', (_, res) => {
res.sendFile(`${HTML_DIR}/hsl.html`);
});
// error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Something broke!');
});
app.use('/', express.static(BASE_DIR));
app.use('/', router);
app.listen(port, () => {
console.log(' listening port ' + port);
});