-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (29 loc) · 974 Bytes
/
index.js
File metadata and controls
39 lines (29 loc) · 974 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
39
const express = require('express');
const {bemhtml} = require('bem-xjst');
const path = require('path');
const fs = require('fs');
console.log('TEST');
const app = express();
const templates = bemhtml.compile();
app.use('/static', express.static(`${__dirname}/build`));
app.get('/index|product', (req, res) => {
const page = req.path.replace('/', '');
const jsonPath = path.resolve(__dirname, 'assets/pages', `${page}.json`);
const bemjson = JSON.parse(fs.readFileSync(jsonPath, {encoding: 'utf-8'}));
const contentHTML = templates.apply(bemjson);
const pageHTML = `
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
${contentHTML}
<script type="text/javascript" src="/static/script.js"></script>
</body>
</html>`
res.send(pageHTML);
});
app.listen(3000, () => {
console.log('App is listening on port 3000');
})