feat(server) layout handling; placekeeper wip

This commit is contained in:
gh0sTedBuddy
2024-03-28 07:07:35 +00:00
parent b6503f1831
commit 0e0b51fa24
8 changed files with 223 additions and 200 deletions

View File

@@ -1,6 +1,7 @@
import { LayServer } from '../src';
import {resolve} from 'path';
import Html from '../src/Views/Html';
import Markdown from '../src/Views/Markdown';
const APP_PORT = Bun.env.APP_PORT ?? Bun.env.PORT ?? 3000;
@@ -36,6 +37,7 @@ class InfoController {
const server = new LayServer({
viewsPath: resolve(__dirname, 'views'),
layout: 'blank.html',
loaders: new Map([[
'html', new Html()
]]),
@@ -43,7 +45,7 @@ const server = new LayServer({
function Main(server) {
server.get('/', async (req, res) => {
return res.json({message: 'hello world'})
}, { domain: 'api.tipedi.local' });
}, { domain: 'example.layc.dev' });
server.all('/data', (req, res) => {
let respBody = `your ${req.method} request was well recieved`;
switch (req.method) {
@@ -86,6 +88,14 @@ server.get('/', async (req, res) => {
return res.render('index');
});
server.get('/blog/:slug', async (req, res) => {
return res.send('index.html', { layout: 'blank.html' });
});
server.use(async (req, res) => {
return res.send('batman');
})
server.listen(APP_PORT, () => {
console.log(`server listen on ${APP_PORT}`);
});