GitHub: https://github.com/Sokhavuth/opine-job
Deno Deploy: https://khmerweb-job.deno.dev/users
In Opine as in Express web frameworks, before building any page, we need to define a route leading to that page first by using Router class in the framework. As the route to the backend under the name “users” was already created by Opine CLI, what we need to do is creating a number of sub-routes to be mounted to this predefined “users” route. In fact, we can create a route leading to the login page, and that route could be mounted to the backend “users” route as below:
// routes/users.ts
import { Router } from "../deps.ts";
const router = Router();
import login from "./users/login.js";
router.use("/", login);
export default router;
// routes/users/login.js
import { Router } from "../../deps.ts";
const router = Router();
import login from "../../controllers/users/login.js";
router.get("/", async (req, res, next) => {
const html = await login.getForm(req);
res.send(html);
});
export default router;
// controllers/users/login.js
import login from "../../views/users/login.jsx";
class Login{
async getForm(req){
const config = req.mysetting();
config.page_title = "Login Page";
config.route = '/users/login';
return await login(config);
}
}
export default new Login();
Top comments (0)