It is necessary for a web application to have a setting page somewhere in the dashboard. Through this page, we can setup many things such as the limitation of items to be loaded into the dashboard and other items on the frontend. However, before doing anything with the setting page, we need to define a route to this page as below:
//route/admin.js
import express from 'express'
const adminRoute = express.Router()
import jobRoute from './admin/job.js'
adminRoute.use('/job',jobRoute)
import categoryRoute from './admin/category.js'
adminRoute.use('/category',categoryRoute)
import uploadRoute from './admin/upload.js'
adminRoute.use('/upload',uploadRoute)
import userRoute from './admin/user.js'
adminRoute.use('/user',userRoute)
import settingRoute from './admin/setting.js'
adminRoute.use('/setting',settingRoute)
export default adminRoute
// route/admin/setting.js
import express from 'express'
const settingRoute = express.Router()
import setting from "../../controller/admin/setting.js"
settingRoute.get('/',async (req,res)=>{
if(req.session.user){
setting.getItem(req,res)
}else{
res.redirect('/login')
}
})
export default settingRoute
// controller/admin/setting.js
import config from '../../config.js'
class Setting{
constructor(){
(async ()=>{
this.config = await config()
})()
}
async getItem(req,res){
this.config.pageTitle = 'ទំព័រ Setting'
this.config.route = '/admin/setting'
res.render('base',{data:this.config})
}
}
export default await new Setting()