-
Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathapp.js
48 lines (34 loc) · 910 Bytes
/
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
42
43
44
45
46
47
48
'use strict';
const http = require('http'),
path = require('path');
const express = require('express');
const morgan = require('morgan');
const app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(morgan('combined'));
app.use(express.static(path.join(__dirname, 'public')));
const articles = [
{ title: 'iPhone 5S', price: 799 },
{ title: 'Lumia 1020', price: 1 }
];
app.get('/', (req, res) => {
// res.send('Hello from Express!');
res.render('index', {
title: 'Hello from Windows container'
});
});
app.get('/error', (req, res) => {
res.send(500);
});
app.get('/articles/:id?', (req, res) => {
if (req.params.id) {
res.send(articles[req.params.id - 1]);
return;
}
res.send(articles);
});
const server = http.createServer(app);
const port = 3000;
console.log('Listening on port', port);
server.listen(port);