// routes/admin.js
import express from 'express'
const adminRouter = express.Router()

import postRouter from './admin/post.js'
adminRouter.use('/post',postRouter)

export default adminRouter

 

// routes/admin/post.js
import express from 'express'
const postRouter = express.Router()
import post from '../../controllers/admin/post.js'

postRouter.get('/',async (req,res)=>{
    if(req.session.user){
        post.getItem(req,res)
    }else{
        res.redirect('/login')
    }
})

export default postRouter

 

// controllers/admin/post.js
import config from '../../config.js'

class Post{
    async getItem(req,res){
        this.config = await config()
        this.config.pageTitle = 'ទំព័រទំនិញ'
        this.config.route = '/admin/post'
        this.config.type = 'post'

        res.render('base',{data:this.config})
    }
}

export default new Post()

 

<!--views/base.ejs-->
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <title><%= data.siteTitle %> | <%= data.pageTitle %></title>
        <link href="/images/siteLogo.png" rel="icon" />
        <link href="/styles/base.css" rel="stylesheet" />
        <link href="/fonts/setup.css" rel="stylesheet" />
        <script src="/scripts/jquery.js"></script>
    </head>
    <body>
        <% if(data.route === '/login'){ %>
            <%- include('./front/login.ejs') %>
        <% }else if(data.route.includes('/admin/')){ %>
            <%- include('./admin/index.ejs') %>
        <% } %>
    </body>
</html>

 

<!--views/admin/index.ejs-->

<section class="Index">
    Admin index
</section>

 

Heroku: https://khmerweb-sale.herokuapp.com/login