A Deno-powered backend service for Plants vs. Zombies: MODDED. [Read-only GitHub mirror]
docs.pvzm.net
express
typescript
expressjs
plant
deno
jspvz
pvzm
game
online
backend
plants-vs-zombies
zombie
javascript
plants
modded
vs
plantsvszombies
openapi
pvz
noads
1import cors from "cors";
2import express from "express";
3import msgpack from "express-msgpack";
4
5import type { ServerConfig } from "./config.ts";
6
7export function createExpressApp(): any {
8 const app = express() as any;
9
10 app.disable("x-powered-by");
11 app.use((_req: any, res: any, next: any) => {
12 res.setHeader("X-Powered-By", "Braaaains...");
13 next();
14 });
15
16 app.use(msgpack());
17
18 return app;
19}
20
21export function setupCors(app: any, config: ServerConfig) {
22 if (config.corsEnabled) {
23 const corsOptions = {
24 origin: function (origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) {
25 if (!origin) return callback(null, true);
26 return callback(null, config.allowedOrigins.includes(origin));
27 },
28 methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
29 allowedHeaders: ["Content-Type", "Accept", "Authorization"],
30 credentials: true,
31 };
32
33 app.use(cors(corsOptions));
34 console.log(`CORS enabled for origins: ${config.allowedOrigins.join(", ") || "none"}`);
35 } else {
36 app.use(cors());
37 console.log("CORS disabled - allowing all origins");
38 }
39}
40
41export function setupBodyParsers(app: any) {
42 app.use(express.json());
43 app.use(
44 express.raw({
45 type: "application/octet-stream",
46 limit: "10mb",
47 })
48 );
49}