-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (33 loc) · 939 Bytes
/
index.js
File metadata and controls
44 lines (33 loc) · 939 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
import "./api/api.js";
import server from "./server/server.js";
import { fileURLToPath } from "node:url";
import path from "node:path";
import express from "express";
const app = express();
const port = 3000;
app.get("/", async (req, res) => {
const html = `
<p>Try the <a href="/server">server</a>, <a href="/client">client</a> or <a href="/static">static</a> versions.</p>
`;
res.send(html);
});
app.use("/client", express.static("client"));
app.get("/client/*", async (req, res) => {
res.sendFile(path.resolve("client/index.html"));
});
app.use(
"/static",
express.static("static/dist", {
extensions: ["html"],
})
);
app.use("/assets", express.static("css"));
app.use("/server", server);
app.listen(port, async () => {
console.log(
`Codelab server started at: http://localhost:${port} <-- Visit this URL`
);
import("./static/static.js");
});