add sessionExpire option
This commit is contained in:
13
mod.ts
13
mod.ts
@@ -13,8 +13,13 @@ type HTTPServerOptions = {
|
||||
staticLocalDir?: string;
|
||||
staticServePath?: string;
|
||||
sessionSecret?: string;
|
||||
sessionExpire?: SessionExpire | number;
|
||||
};
|
||||
|
||||
export enum SessionExpire {
|
||||
NEVER = 2147483647,
|
||||
}
|
||||
|
||||
export enum HTTPMethod {
|
||||
GET = "GET",
|
||||
POST = "POST",
|
||||
@@ -277,7 +282,9 @@ export class HTTPServer {
|
||||
sessionObject,
|
||||
this.settings?.sessionSecret,
|
||||
);
|
||||
routeReply.cookie("session", encodedSession);
|
||||
routeReply.cookie("session", encodedSession, {
|
||||
maxAge: this.settings.sessionExpire ?? undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,9 +440,9 @@ export class RouteRequest {
|
||||
sessionCookie,
|
||||
httpServer.settings.sessionSecret,
|
||||
);
|
||||
try{
|
||||
try {
|
||||
this.session = JSON.parse(decodedSessionCookie);
|
||||
}catch(_err){
|
||||
} catch (_err) {
|
||||
// Ignore if sessionCookie is not in JSON format
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user