UNPKG

@aj-archipelago/cortex

Version:

Cortex is a GraphQL API for AI. It provides a simple, extensible interface for using AI services from OpenAI, Azure and others.

36 lines (31 loc) 775 B
import {Hono} from "hono"; import {cors} from 'hono/cors'; import {serveStatic} from '@hono/node-server/serve-static'; export class ApiServer { private readonly apiKey: string; private readonly app: Hono; private readonly corsHosts: string; constructor(apiKey: string, corsHosts: string) { this.apiKey = apiKey; this.app = new Hono(); this.corsHosts = corsHosts; } getServer() { return this.app; } initServer() { this.app.use( '/api/*', cors({ origin: this.corsHosts, }) ) this.app.get('/api/health', (c) => { return c.json({status: 'ok'}); }); this.app.post('/api/echo', (c) => { return c.json(c.body); }); this.app.use('*', serveStatic({ root: './client/build' })) } }