enhance: detect requests of pwa

This commit is contained in:
Julian Krauser 2025-01-11 14:45:37 +01:00
parent 632a8290ac
commit b1e949dce2
3 changed files with 14 additions and 0 deletions

View file

@ -12,6 +12,7 @@ declare global {
username: string;
isOwner: boolean;
permissions: PermissionObject;
isPWA: boolean;
}
}
}

View file

@ -0,0 +1,11 @@
import { Request, Response } from "express";
export default async function detectPWA(req: Request, res: Response, next: Function) {
const userAgent = req.headers["user-agent"] || "";
if ((userAgent.includes("Mobile") && userAgent.includes("Standalone")) || req.headers["x-pwa-client"] === "true") {
req.isPWA = true;
} else {
req.isPWA = false;
}
next();
}

View file

@ -13,6 +13,7 @@ import reset from "./reset";
import auth from "./auth";
import admin from "./admin/index";
import user from "./user";
import detectPWA from "../middleware/detectPWA";
export default (app: Express) => {
app.set("query parser", "extended");
@ -25,6 +26,7 @@ export default (app: Express) => {
app.use(cors());
app.options("*", cors());
app.use(detectPWA);
app.use("/api/public", publicAvailable);
app.use("/api/setup", allowSetup, setup);
app.use("/api/reset", reset);