Skip to content

Commit d456077

Browse files
committed
Merge branch 'express-v5'
2 parents 5a792d5 + 2a1aa47 commit d456077

19 files changed

+2083
-3165
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# uWebSockets.js + Express
22

3-
Express API compatibility layer for uWebSockets.js.
3+
Express API compatibility layer for [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js).
44

55
## Usage
66

build.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ async function main() {
2525
declaration: true,
2626
emitDeclarationOnly: true,
2727
skipLibCheck: true,
28-
module: "commonjs",
29-
target,
28+
module: ts.ModuleKind.CommonJS,
29+
target: ts.ScriptTarget.ES2017,
3030
outDir: outdir,
3131
esModuleInterop: true,
3232
experimentalDecorators: true,

example/async_test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import uWS from "uWebSockets.js";
2-
import express from "express";
2+
// import express from "express";
33
import expressify from "../src";
44

55
// import promisified timers
@@ -8,7 +8,7 @@ import { setTimeout } from "timers/promises";
88
const PORT = 8080;
99
const app = expressify(uWS.App());
1010

11-
app.get('/', async (req, res) => {
11+
app.get('/', async function asyncGet(req, res) {
1212
res.header("Cache-Control", "no-cache, no-store, must-revalidate");
1313
await setTimeout(1000);
1414

@@ -17,4 +17,4 @@ app.get('/', async (req, res) => {
1717
res.end();
1818
});
1919

20-
app.listen(PORT, () => console.log(`Listening on ${PORT}`));
20+
app.listen(PORT, () => console.log(`Listening on http://localhost:${PORT}`));

example/experiment.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ app.get('/test', (_req, res) => {
3636

3737
app.use('/colyseus', root);
3838

39-
app.listen(8080);
40-
console.log("Listening on 8080");
39+
app.listen(8080, () => console.log("Listening on http://localhost:8080"));

example/express_router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ monitor.get("/api", (req, res) => res.json({ data: [1, 2, 3, 4, 5] }));
3636
app.use("/monitor", monitor);
3737

3838

39-
app.listen(PORT);
39+
app.listen(PORT, () => console.log(`Server is running on http://localhost:${PORT}`));

example/middleware_serve_index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ const app = expressify(uWS.App());
1010
app.use('/', serveIndex(path.join(__dirname, ".."), { icons: true, hidden: true }))
1111
app.use('/', express.static(path.join(__dirname, "..")));
1212

13-
app.listen(PORT, () => console.log("Listening on", PORT));
13+
app.listen(PORT, () => console.log(`Listening on http://localhost:${PORT}`));

example/middleware_session.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import express from "express";
2-
import expressify from "../src";
31
import uWS from "uWebSockets.js";
4-
52
import session from "express-session";
3+
import expressify from "../src";
64

75
const PORT = 8080;
8-
96
const app = expressify(uWS.App());
107

11-
// app.use(cookieParser());
12-
138
// Use the session middleware
149
app.use(session({
1510
secret: "shhh",

example/middleware_static.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ const PORT = 8080;
88
const app = expressify(uWS.App());
99
app.use('/', express.static(path.join(__dirname, "static")));
1010

11-
app.listen(PORT, () => console.log("Listening on", PORT));
11+
app.listen(PORT, () => console.log(`Listening on http://localhost:${PORT}`));

example/render.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ app.get("/render", (req, res) => {
2929

3030
app.get("/redirect", (req, res) => {
3131
console.log("Let's redirect back!");
32-
res.redirect('back');
32+
res.redirect(req.get('Referrer') || '/')
3333
});
3434

35-
app.listen(PORT, () => console.log(`Listening at ${PORT}`));
35+
app.listen(PORT, () => console.log(`Listening at http://localhost:${PORT}`));

example/uwebsockets_express.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import uWS from "uWebSockets.js";
22
import express from "express";
3-
import expressify from "../src";
3+
import expressify, { ServerResponse } from "../src";
4+
5+
// // @ts-ignore
6+
// const res = new ServerResponse(undefined, undefined, undefined);
7+
// // @ts-ignore
8+
// res.setHeader("X-Test", "test");
9+
// process.exit();
410

511
const PORT = 8080;
612

@@ -12,7 +18,8 @@ users.get("/param/:id", (req, res) => res.json({ id: req.params.id }));
1218
const app = expressify(uWS.App());
1319
app.use("/users", users);
1420

15-
app.get('/', (req, res) => res.send("Hello world!"));
21+
app.get('/', function getRoot (req, res) {
22+
res.send("Hello world!");
23+
});
1624

17-
app.listen(PORT);
18-
console.log("Server is running on port http://localhost:" + PORT);
25+
app.listen(PORT, () => console.log(`Listening on http://localhost:${PORT}`));

0 commit comments

Comments
 (0)