import { Hono } from 'hono';
import { jsxRenderer } from 'hono/jsx-renderer';
import { Page } from '@blog/templates/Page';
import home from '@blog/handlers/home';
import posts from '@blog/handlers/posts';
import type { SiteMeta } from '@blog/models/SiteMeta';

declare module 'hono' {
  interface ContextRenderer {
    (content: string|Promise<string>, props: { meta: SiteMeta }): Response;
  }
}

const app = new Hono();

// Render the JSX views
app.get(
  '*',
  jsxRenderer(
    ({ children, meta }) => <Page meta={meta}>{children}</Page>,
    { docType: true }
  )
);

console.log({ message: "Bootstrapping the routes..." });
app.route('/', home);
app.route('/posts', posts);

export default {
  port: process.env.APP_PORT || 3000,
  fetch: app.fetch
}

