Merge pull request #8 from Fretuks/fix-session-file-store-errors
Ensure session storage directory exists and use resolved path
This commit is contained in:
@@ -12,12 +12,17 @@ const modelState = new Map();
|
|||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 3000;
|
const PORT = 3000;
|
||||||
const DB_PATH = "./data/app.db";
|
const DB_PATH = "./data/app.db";
|
||||||
|
const SESSIONS_DIR = path.resolve("sessions");
|
||||||
const UNLOAD_AFTER_MS = 30 * 1000;
|
const UNLOAD_AFTER_MS = 30 * 1000;
|
||||||
|
|
||||||
if (!fs.existsSync("./data")) {
|
if (!fs.existsSync("./data")) {
|
||||||
fs.mkdirSync("./data", {recursive: true});
|
fs.mkdirSync("./data", {recursive: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(SESSIONS_DIR)) {
|
||||||
|
fs.mkdirSync(SESSIONS_DIR, {recursive: true});
|
||||||
|
}
|
||||||
|
|
||||||
function scheduleModelUnload(model) {
|
function scheduleModelUnload(model) {
|
||||||
if (!modelState.has(model)) {
|
if (!modelState.has(model)) {
|
||||||
modelState.set(model, {timer: null, activeRequests: 0});
|
modelState.set(model, {timer: null, activeRequests: 0});
|
||||||
@@ -470,7 +475,7 @@ app.use(bodyParser.json());
|
|||||||
app.use(express.static("public"));
|
app.use(express.static("public"));
|
||||||
app.use(
|
app.use(
|
||||||
session({
|
session({
|
||||||
store: new FileStore({path: "./sessions"}),
|
store: new FileStore({path: SESSIONS_DIR}),
|
||||||
secret: "-secret-key-here-",
|
secret: "-secret-key-here-",
|
||||||
resave: false,
|
resave: false,
|
||||||
saveUninitialized: false,
|
saveUninitialized: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user