-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
133 lines (121 loc) · 3.38 KB
/
server.js
File metadata and controls
133 lines (121 loc) · 3.38 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const serverPort = process.env.SERVER_PORT ? process.env.SERVER_PORT : 3000
const express = require('express')
const cors = require('cors')
const app = express()
app.use(cors())
// It parses incoming requests with JSON payloads and is based on body-parser
app.use(express.json())
// middleware for logging
app.use(function (req, res, next) {
contentLenght = req.headers['content-length'] ? req.headers['content-length'] : ''
transactionId = req.body.transactionId ? req.body.transactionId : ''
origin = req.body.origin ? req.body.origin : ''
pathname = req.body.pathname ? req.body.pathname : ''
console.log(`${new Date().toISOString()} ${req.method} ${req.originalUrl} ${origin} ${pathname.replace(/(.{30})..+/, "$1…")} ${contentLenght}`)
next()
})
// healthcheck
app.get('/health', (req, res) => {
res.send('BattlePage API is ready!')
})
// demo
app.get('/lazy-request', (req, res) => {
setTimeout(function(){
res.send({'a':10})
}, 5000)
})
app.get('/items', function(req, res) {
let start = Date.now()
res.set('Server-Timing', `server;dur=${Date.now() - start}`)
res.json([
{
'name':'Madmonq Amumu',
'path': './src/madmonq/madmonq_amumu_wallpaper.jpg',
'price': '515 CZK'
},
{
'name':'Nomad Tumbler',
'path': './src/madmonq/madmonq_badges_wallpaper_1920x1080.png',
'price': '35 CZK'
},
{
'name':'Focus Paper Refill',
'path': './src/madmonq/madmonq_beauty_setup.png',
'price': '89 CZK'
},
{
'name':'Machined Mechanical Pencil',
'path': './src/madmonq/madmonq_doom_wallpaper.jpg',
'price': '35 CZK'
},
{
'name':'Innkeeper',
'path': './src/other/Waves_Dark_Alt_6016x6016.jpg',
'price': '108 CZK'
},
{
'name':'Posters',
'path': './src/other/Waves_Monterey_Light_6016x6016.jpg',
'price': '80 CZK'
},
{
'name':'Posters 2',
'path': './src/other/Waves_Light_6016x6016.jpg',
'price': '160 CZK'
},
{
'name':'Flatlay',
'path': './src/other/Waves_Dark_Alt_6016x6016.jpg',
'price': '515 CZK'
}
])
})
app.get('/items-optimized', function(req, res) {
let start = Date.now()
res.set('Server-Timing', `server;dur=${Date.now() - start}`)
res.json([
{
'name':'Madmonq Amumu',
'path': './src/madmonq/madmonq_amumu_wallpaper.avif',
'price': '515 CZK'
},
{
'name':'Nomad Tumbler',
'path': './src/madmonq/madmonq_badges_wallpaper_1920x1080.avif',
'price': '35 CZK'
},
{
'name':'Focus Paper Refill',
'path': './src/madmonq/madmonq_beauty_setup.avif',
'price': '89 CZK'
},
{
'name':'Machined Mechanical Pencil',
'path': './src/madmonq/madmonq_doom_wallpaper.avif',
'price': '35 CZK'
},
{
'name':'Innkeeper',
'path': './src/other/Waves_Dark_Alt_6016x6016.avif',
'price': '108 CZK'
},
{
'name':'Posters',
'path': './src/other/Waves_Monterey_Light_6016x6016.avif',
'price': '80 CZK'
},
{
'name':'Posters 2',
'path': './src/other/Waves_Light_6016x6016.avif',
'price': '160 CZK'
},
{
'name':'Flatlay',
'path': './src/other/Waves_Dark_Alt_6016x6016.avif',
'price': '515 CZK'
}
])
})
app.listen(serverPort, () => {
console.log(`${new Date().toISOString()} BattlePage server listening on port ${serverPort}`)
})