enhance: detect requests of pwa
This commit is contained in:
parent
632a8290ac
commit
b1e949dce2
3 changed files with 14 additions and 0 deletions
|
@ -12,6 +12,7 @@ declare global {
|
||||||
username: string;
|
username: string;
|
||||||
isOwner: boolean;
|
isOwner: boolean;
|
||||||
permissions: PermissionObject;
|
permissions: PermissionObject;
|
||||||
|
isPWA: boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
src/middleware/detectPWA.ts
Normal file
11
src/middleware/detectPWA.ts
Normal 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();
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ import reset from "./reset";
|
||||||
import auth from "./auth";
|
import auth from "./auth";
|
||||||
import admin from "./admin/index";
|
import admin from "./admin/index";
|
||||||
import user from "./user";
|
import user from "./user";
|
||||||
|
import detectPWA from "../middleware/detectPWA";
|
||||||
|
|
||||||
export default (app: Express) => {
|
export default (app: Express) => {
|
||||||
app.set("query parser", "extended");
|
app.set("query parser", "extended");
|
||||||
|
@ -25,6 +26,7 @@ export default (app: Express) => {
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.options("*", cors());
|
app.options("*", cors());
|
||||||
|
|
||||||
|
app.use(detectPWA);
|
||||||
app.use("/api/public", publicAvailable);
|
app.use("/api/public", publicAvailable);
|
||||||
app.use("/api/setup", allowSetup, setup);
|
app.use("/api/setup", allowSetup, setup);
|
||||||
app.use("/api/reset", reset);
|
app.use("/api/reset", reset);
|
||||||
|
|
Loading…
Reference in a new issue