diff --git a/models/blog.js b/models/blog.js index 89bf9bb..83b7503 100644 --- a/models/blog.js +++ b/models/blog.js @@ -91,7 +91,6 @@ const blogSchema = new mongoose.Schema({ }); // Indexes -blogSchema.index({ slug: 1 }); blogSchema.index({ status: 1, createdAt: -1 }); blogSchema.index({ category: 1, status: 1 }); blogSchema.index({ isFeatured: 1, status: 1 }); diff --git a/models/blogCategory.js b/models/blogCategory.js index 7e342f1..66d1b6a 100644 --- a/models/blogCategory.js +++ b/models/blogCategory.js @@ -30,7 +30,6 @@ const blogCategorySchema = new mongoose.Schema({ }); // Indexes -blogCategorySchema.index({ slug: 1 }); blogCategorySchema.index({ isActive: 1, name: 1 }); // Remove __v from JSON output diff --git a/models/blogTag.js b/models/blogTag.js index 8db8d9c..9d89ebe 100644 --- a/models/blogTag.js +++ b/models/blogTag.js @@ -26,7 +26,6 @@ const blogTagSchema = new mongoose.Schema({ }); // Indexes -blogTagSchema.index({ slug: 1 }); blogTagSchema.index({ isActive: 1, name: 1 }); // Remove __v from JSON output diff --git a/models/visa.js b/models/visa.js index 6edae4e..60855be 100644 --- a/models/visa.js +++ b/models/visa.js @@ -179,9 +179,10 @@ const DetailedViewSchema = new mongoose.Schema( // Main VisaCountry Schema (Individual country object) const VisaCountrySchema = new mongoose.Schema( { - id: { type: Number, required: true, index: true }, - name: { type: String, required: true, index: true }, - slug: { type: String, required: true, unique: true, index: true }, + // Không dùng `index: true` ở đây vì đã tạo index riêng cho hero.summaryList.* bên dưới + id: { type: Number, required: true }, + name: { type: String, required: true }, + slug: { type: String, required: true, unique: true }, icon: { type: String, default: "" }, services: { type: [String], diff --git a/package.json b/package.json index f8210bc..a3fddd9 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "express": "^4.18.2", "express-ejs-layouts": "^2.5.1", "express-session": "^1.17.3", + "connect-mongo": "^5.1.0", "i18n": "^0.15.1", "mongoose": "^8.16.1", "multer": "^1.4.5-lts.1", diff --git a/server.js b/server.js index 1378ddd..924d8f0 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,7 @@ const dotenv = require("dotenv"); const path = require("path"); const cookieParser = require("cookie-parser"); const session = require("express-session"); +const MongoStore = require("connect-mongo"); const flash = require("connect-flash"); const expressLayouts = require("express-ejs-layouts"); const fs = require("fs"); @@ -56,13 +57,22 @@ app.use( // Serve other public files app.use(express.static(path.join(__dirname, "public"))); -// Session configuration +// Session configuration (using MongoDB store to avoid logout khi server restart) app.use( session({ secret: process.env.SESSION_SECRET || "secret", - resave: true, + resave: false, saveUninitialized: false, - cookie: { maxAge: 1000 * 60 * 60 * 24 }, // 24 hours + store: MongoStore.create({ + mongoUrl: process.env.MONGODB_URI, + collectionName: "sessions", + ttl: 60 * 60 * 24, // 24 hours (in seconds) + }), + cookie: { + maxAge: 1000 * 60 * 60 * 24, // 24 hours + httpOnly: true, + sameSite: "lax", + }, }), ); diff --git a/views/admin/dashboard.ejs b/views/admin/dashboard.ejs index d6a9534..a72f79b 100644 --- a/views/admin/dashboard.ejs +++ b/views/admin/dashboard.ejs @@ -230,7 +230,7 @@ -
Manage blog posts
+