add sessionExpire option
This commit is contained in:
parent
d519c7bf9c
commit
5392b032d0
@ -1,6 +1,6 @@
|
||||
import { Status } from "https://deno.land/std@0.186.0/http/http_status.ts";
|
||||
import prettyTime from "npm:pretty-time";
|
||||
import { HTTPServer } from "../mod.ts";
|
||||
import { HTTPServer, SessionExpire } from "../mod.ts";
|
||||
|
||||
const JOKES = [
|
||||
"Why do Java developers often wear glasses? They can't C#.",
|
||||
@ -194,4 +194,5 @@ httpServer.listen({
|
||||
staticLocalDir: "/static",
|
||||
staticServePath: "/assets",
|
||||
sessionSecret: "SuperDuperSecret",
|
||||
sessionExpire: SessionExpire.NEVER
|
||||
});
|
||||
|
9
mod.ts
9
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user