Skip to content

Conversation

@markusahlstrand
Copy link
Owner

Replace the first couple of handlers with hono-handlers.

You can now use the proxy like this (with typescript):

import { Hono } from 'hono';

import packageJson from '../package.json';
import { Env } from './types/Env';
import { registerRoutes } from '../../../src/';
import { basicAuth } from 'hono/basic-auth';
import { cache } from 'hono/cache';

const app = new Hono<Env>();

app.get('/', async () => {
  return new Response(
    JSON.stringify({
      name: packageJson.name,
      version: packageJson.version,
    }),
  );
});

registerRoutes(app, [
  {
    path: '/test',
    methods: 'GET',
    handler: basicAuth({ username: 'test', password: 'password' }),
  },
  {
    path: '/test',
    methods: 'GET',
    handler: async () => new Response('Raw response'),
  },
  {
    path: '/cache',
    methods: 'GET',
    handler: cache({ cacheName: 'test' }),
  },
  {
    path: '/cache',
    methods: 'GET',
    handler: async () =>
      new Response(`Cachable response at ${new Date().toISOString()}`, {
        headers: {
          'Cache-Control': 'max-age=10',
        },
      }),
  },
]);

export default app;

@markusahlstrand markusahlstrand mentioned this pull request Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants