diff --git a/src/index.ts b/src/index.ts index 193e7e5..aa3cbe1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,19 +29,19 @@ if (!fs.existsSync(path.join(process.cwd(), ".env"))) { const secret = PasswordGen(24) const rString = ` - port=80 - altregion=us # the displayed region in each page's header +port=80 +altregion=us # the displayed region in each page's header - servicename=File Server # the displayed service name in each page's header - description=A simple file server built with Express. # the displayed description in the home page +servicename=File Server # the displayed service name in each page's header +description=A simple file server built with Express. # the displayed description in the home page - bootmessage=Welcome! +bootmessage=Welcome! - session_secret=${secret} # the session secret used for logins. you can generate a new secret using the idGen command. - enable_register=false # it's advised to keep this off unless you're hosting a public instance +session_secret=${secret} # the session secret used for logins. you can generate a new secret using the idGen command. +enable_register=false # it's advised to keep this off unless you're hosting a public instance - postwrite_notice=Hi! # the notice on top of the post form - postwrite_html=false # if enabled, users can use html in posts. this is unsafe! you can set it to true if you trust your users. +postwrite_notice=Hi! # the notice on top of the post form +postwrite_html=false # if enabled, users can use html in posts. this is unsafe! you can set it to true if you trust your users. ` fs.writeFileSync(path.join(process.cwd(), ".env"), rString); @@ -74,7 +74,7 @@ export var server: Server; import moment from 'moment-timezone' import { Server } from "http"; -import session from "express-session"; +import session, { MemoryStore, Store } from "express-session"; var accessLogStream = fs.createWriteStream('./pvfiles/interactions.log', { flags: 'a' }); @@ -88,15 +88,17 @@ try { filename: (req, file, cb) => cb(null, `${Date.now()}_${file.originalname}`) }) - upload = multer({storage}) + upload = multer({ storage }) app.use( session({ name: "session", + store: new MemoryStore(), secret: process.env.session_secret, resave: false, saveUninitialized: false, cookie: { + maxAge: Date.now() + (30 * 24 * 3600 * 1000), httpOnly: true, sameSite: "lax", secure: dev diff --git a/src/pages/login.ts b/src/pages/login.ts index a2b081d..751e17e 100644 --- a/src/pages/login.ts +++ b/src/pages/login.ts @@ -91,7 +91,7 @@ export async function Main(app: Express) { username: user.username }; - res.redirect("/"); + res.redirect(req.query?.next?.toString() ?? "/"); } ); }); diff --git a/src/pages/posts.ts b/src/pages/posts.ts index 3d0c1a0..0b8bd22 100644 --- a/src/pages/posts.ts +++ b/src/pages/posts.ts @@ -185,7 +185,7 @@ export async function Main(app: Express) {
- ` : `Log in to create posts.
`} + ` : `Log in to create posts.
`}You must be logged in to create a post.
Server region: ${'(alternate) ' + process.env.altregion}
-Logged in as ${req.session.user.username}
- log out