-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode3_6.js
More file actions
28 lines (23 loc) · 732 Bytes
/
Copy pathcode3_6.js
File metadata and controls
28 lines (23 loc) · 732 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
const express = require('express');
const port = 3000;
const app = express();
app.set('views', `${__dirname}/views`);
app.set('view engine', 'pug');
app.get('/', (req, res) => res.render('index.pug'));
app.get('/page', (req, res) => {
const { page } = req.query;
res.render('board.pug', { page });
console.log(typeof page);
});
app.get('/posts', (req, res) => {
const { until } = req.query;
const untilParsed = parseInt(until, 10);
const posts = [];
if (!isNaN(untilParsed)) {
for (let i = 0; i < untilParsed; i++) {
posts.push(`Post ${i + 1}`);
}
}
res.render('posts.pug', { posts });
});
app.listen(port, () => console.log(`Server listening on port ${port}!`));