-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (39 loc) · 1.14 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
// Don't edit any code in this file
import express from "express";
import cors from "cors";
import serveIndex from "serve-index";
const app = express();
const port = 3000;
const publicDir = process.cwd() + "/demos";
function sleep(ms = 1000) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms);
});
}
app.use(cors());
app.get("/cache-demo", async (req, res) => {
const result = Object.values(req.query).join("_");
await sleep();
res.send(`COUPON_${result.toUpperCase()}`);
});
app.get("/error", async (req, res) => {
res.status(500).send(`Simulated error from the server`);
});
app.get("/cookie-server", (req, res, next) => {
res.cookie("codelab_some_private_info", "private_value", {
httpOnly: true,
});
res.cookie("codelab_color_scheme", "dark");
res.cookie("codelab_registered", "true");
res.cookie("codelab_server_key", "12345", {
httpOnly: true,
});
next();
});
app.use(express.static(publicDir));
app.use("/", serveIndex(publicDir, { icons: true }));
app.listen(port, () => {
console.log(`App running at http://localhost:${port}`);
});