mirror of
https://github.com/nvms/prsm.git
synced 2025-12-16 16:10:54 +00:00
rm unused
This commit is contained in:
parent
66b85e8695
commit
c55dcce258
@ -1,54 +1,9 @@
|
|||||||
import ms from "@prsm/ms";
|
|
||||||
import cookieParser from "cookie-parser";
|
|
||||||
import { randomBytes } from "crypto";
|
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import session, { MemoryStore } from "express-session";
|
|
||||||
|
|
||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
|
|
||||||
export const isValidEmail = (email: string) => emailRegex.test(email);
|
export const isValidEmail = (email: string) => emailRegex.test(email);
|
||||||
|
|
||||||
// const isMiddlewareUsed = (app: express.Application, name: string) =>
|
|
||||||
// !!app._router.stack.filter(
|
|
||||||
// (layer: { handle: { name: string } }) =>
|
|
||||||
// layer && layer.handle && layer.handle.name === name,
|
|
||||||
// ).length;
|
|
||||||
|
|
||||||
// export const ensureRequiredMiddlewares = (app: express.Application) => {
|
|
||||||
// const requiredMiddlewares = [
|
|
||||||
// {
|
|
||||||
// name: "cookieParser",
|
|
||||||
// handler: () => cookieParser(),
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: "session",
|
|
||||||
// handler: () =>
|
|
||||||
// session({
|
|
||||||
// store: new MemoryStore({ captureRejections: true }),
|
|
||||||
// name: "pine",
|
|
||||||
// secret: randomBytes(32).toString("hex"),
|
|
||||||
// resave: false,
|
|
||||||
// saveUninitialized: true,
|
|
||||||
// cookie: {
|
|
||||||
// secure: process.env.NODE_ENV === "production",
|
|
||||||
// maxAge: ms("30m"),
|
|
||||||
// httpOnly: !(process.env.NODE_ENV === "production"),
|
|
||||||
// sameSite: "lax",
|
|
||||||
// },
|
|
||||||
// }),
|
|
||||||
// },
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// for (const { name, handler } of requiredMiddlewares) {
|
|
||||||
// if (!isMiddlewareUsed(app, name)) {
|
|
||||||
// console.warn(
|
|
||||||
// `Required middleware '${name}' not found. It will automatically be used and you may not agree with the default configuration.`,
|
|
||||||
// );
|
|
||||||
// app.use(handler());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
const isMiddlewareUsed = (app: express.Application, name: string) =>
|
const isMiddlewareUsed = (app: express.Application, name: string) =>
|
||||||
!!app._router.stack.filter(
|
!!app._router.stack.filter(
|
||||||
(layer: { handle: { name: string } }) =>
|
(layer: { handle: { name: string } }) =>
|
||||||
@ -61,7 +16,7 @@ export const ensureRequiredMiddlewares = (app: express.Application) => {
|
|||||||
for (const name of requiredMiddlewares) {
|
for (const name of requiredMiddlewares) {
|
||||||
if (!isMiddlewareUsed(app, name)) {
|
if (!isMiddlewareUsed(app, name)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Required middleware '${name}' not found. Please ensure it is added to your express application.`
|
`Required middleware '${name}' not found. Please ensure it is added to your express application.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user