// routes/index.js

import { Router } from "../deps.ts"
const router = Router()

import home from './front/home.js'
router.use('/', home)

import login from './front/login.js'
router.use('/login', login)

import post from './front/post.js'
router.use('/post', post)

export default router

 

// routes/front/home.js

import { Router } from "../../deps.ts"
const router = Router()

import post from '../../controllers/front/post.js'

router.get('/:id', async (req, res) => {
    post.getOneItem(req, res)
})

export default router

 

// controllers/front/post.js

import config from '../../config.js'
import post from '../../views/front/post.jsx'
import postdb from '../../models/postdb.ts'

class Post{
    async getOneItem(req, res){
        this.config = await config()
        this.config.pageTitle = 'ទំព័រ​ការផ្សាយ'
        this.config.route = '/'

        let {item} = await postdb.getItem(req, 0)
        this.config.post = item

        const html = await post(this.config)
        res.send(html)
    }
}

export default new Post()

 

GitHub: https://github.com/Sokhavuth/khmerweb-deno

Deno Deploy: https://khmerweb-blog.deno.dev