-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathserver.ts
More file actions
31 lines (22 loc) · 755 Bytes
/
Copy pathserver.ts
File metadata and controls
31 lines (22 loc) · 755 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
import Router from "@koa/router";
import {createSession} from "better-sse";
import Koa from "koa";
import serve from "koa-static";
import {getPublicDirPath} from "../utils";
import {KoaConnection} from "./connections/KoaConnection";
const app = new Koa();
const router = new Router();
app.use(serve(getPublicDirPath(__dirname)));
KoaConnection.addListeners(app);
router.get("/sse", async (ctx) => {
const connection = new KoaConnection(ctx);
const session = await createSession(connection);
session.push("Hello world!", "ping");
});
app.use(router.routes()).use(router.allowedMethods());
const PORT = process.env.PORT ?? 8080;
app.listen(PORT, () => {
console.log(
`Server listening. Open http://localhost:${PORT} in your browser.`
);
});