abhijanb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/app.ts +14 -0
- package/index.ts +20 -0
- package/package.json +22 -0
- package/rateLimiter.ts +14 -0
- package/socket.ts +10 -0
package/README.md
ADDED
package/app.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import http from "http";
|
|
3
|
+
|
|
4
|
+
const app = express();
|
|
5
|
+
const server = http.createServer(app);
|
|
6
|
+
|
|
7
|
+
/** Express app instance — use for routing and middleware */
|
|
8
|
+
export { app };
|
|
9
|
+
/** HTTP server instance — used by Socket.IO */
|
|
10
|
+
export { server };
|
|
11
|
+
/** Express request type */
|
|
12
|
+
export type { Request, Response, NextFunction } from "express";
|
|
13
|
+
/** Router — create modular route handlers */
|
|
14
|
+
export { Router, json, urlencoded, static as expressStatic } from "express";
|
package/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Express app instance — use for routing and middleware */
|
|
2
|
+
export { app, server } from "./app";
|
|
3
|
+
/** Express types — Request, Response, NextFunction */
|
|
4
|
+
export type { Request, Response, NextFunction } from "./app";
|
|
5
|
+
/** Express utilities — Router, json, urlencoded, expressStatic */
|
|
6
|
+
export { Router, json, urlencoded, expressStatic } from "./app";
|
|
7
|
+
|
|
8
|
+
/** Socket.IO server instance — use for `.on()` / `.emit()` */
|
|
9
|
+
export { io, socket } from "./socket";
|
|
10
|
+
/** Socket type — for typing event handlers */
|
|
11
|
+
export type { Socket } from "./socket";
|
|
12
|
+
|
|
13
|
+
/** Rate limiter factory: `app.use(limiter(5, 1000))` = 5min window, 1000 req/IP */
|
|
14
|
+
export { limiter } from "./rateLimiter";
|
|
15
|
+
/** Factory — create custom rate limiters: `rateLimit({ windowMs: 60000, max: 20 })` */
|
|
16
|
+
export { rateLimit } from "./rateLimiter";
|
|
17
|
+
|
|
18
|
+
/** Default export — Express app instance */
|
|
19
|
+
import { app } from "./app";
|
|
20
|
+
export default app;
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "abhijanb",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"module": "index.ts",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./index.ts"
|
|
8
|
+
},
|
|
9
|
+
"types": "./index.ts",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"express": "^4.21.0",
|
|
12
|
+
"express-rate-limit": "^7.5.0",
|
|
13
|
+
"socket.io": "^4.8.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/bun": "latest",
|
|
17
|
+
"@types/express": "^5.0.0"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"typescript": "^5"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/rateLimiter.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import rateLimit from "express-rate-limit";
|
|
2
|
+
|
|
3
|
+
/** Factory — create a rate limiter: `app.use(limiter(5, 1000))` = 5min window, 1000 req/IP */
|
|
4
|
+
const limiter = (minutes: number = 5, max: number = 100) =>
|
|
5
|
+
rateLimit({
|
|
6
|
+
windowMs: minutes * 60 * 1000,
|
|
7
|
+
max,
|
|
8
|
+
standardHeaders: true,
|
|
9
|
+
legacyHeaders: false,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { limiter };
|
|
13
|
+
/** Low-level factory — create rate limiters with full config object */
|
|
14
|
+
export { rateLimit };
|
package/socket.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Server } from "socket.io";
|
|
2
|
+
import { server } from "./app";
|
|
3
|
+
|
|
4
|
+
const io = new Server(server);
|
|
5
|
+
const socket = io;
|
|
6
|
+
|
|
7
|
+
/** Socket.IO server instance — use for `.on()` / `.emit()` */
|
|
8
|
+
export { io, socket };
|
|
9
|
+
/** Socket type — for typing event handlers */
|
|
10
|
+
export type { Socket } from "socket.io";
|