forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (26 loc) · 837 Bytes
/
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
/* eslint-disable no-console */
const { send, createError } = require('micro')
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing
const formatServerTiming = (items) => {
const toTiming = (item) => {
return `${item.name};desc="${item.description}";dur=${item.duration}`
}
return items.map(toTiming).join(', ')
}
module.exports = async (req, res) => {
if (req.url === '/favicon.ico') {
return send(res, 404)
}
if (req.url === '/') {
res.setHeader('Content-Type', 'text/html')
const value = formatServerTiming([{
name: 'cache',
description: 'my example',
duration: 2002,
}])
res.setHeader('Server-Timing', value)
return send(res, 200, '<body><h1>Hi there</h1></body>')
}
console.log('req "%s"', req.url)
throw createError(500, 'Unknown path')
}