58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { Hono } from 'hono';
|
|
import { serveStatic } from 'hono/bun';
|
|
import { join } from 'path';
|
|
import { tokenService } from './token-service';
|
|
import { createAuthRoutes } from './auth-routes';
|
|
import { createJobsRoutes } from './jobs-routes';
|
|
|
|
// temporary: dev-only SSL bypass for upstream PocketBase cert issues
|
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
|
|
// PERMANENT: Load environment variables
|
|
// Check if POCKETBASE_URL is set, use default if not
|
|
if (!process.env.POCKETBASE_URL) {
|
|
process.env.POCKETBASE_URL = 'https://pocketbase.ccllc.pro';
|
|
console.log('[Mode2Test] Using default POCKETBASE_URL:', process.env.POCKETBASE_URL);
|
|
}
|
|
|
|
// PERMANENT: Initialize token service and start background refresh
|
|
// Loads existing tokens from file if available
|
|
// Starts 5-minute background refresh cycle
|
|
tokenService.initialize();
|
|
tokenService.startBackgroundRefresh();
|
|
|
|
// Create Hono app
|
|
const app = new Hono();
|
|
|
|
// Mount auth routes
|
|
app.route('/api/auth', createAuthRoutes());
|
|
|
|
// Mount jobs routes
|
|
app.route('/api/jobs', createJobsRoutes());
|
|
|
|
// Health check endpoint
|
|
app.get('/health', (c) => {
|
|
return c.text('OK');
|
|
});
|
|
|
|
// Version endpoint
|
|
app.get('/version', (c) => {
|
|
return c.json({ version: '1.0.0-beta1' });
|
|
});
|
|
|
|
// PERMANENT: Serve static frontend files
|
|
// Serves from frontend/ directory
|
|
const publicDir = join(import.meta.dir, '../frontend');
|
|
app.use('/*', serveStatic({ root: publicDir }));
|
|
|
|
// Start server on port 3005
|
|
const port = 3005;
|
|
console.log(`Mode2Test (AuthAndToken) running on http://localhost:${port}`);
|
|
console.log(`Auth API: /api/auth/*`);
|
|
console.log(`SignIn page: /signin.html`);
|
|
|
|
export default {
|
|
fetch: app.fetch,
|
|
port,
|
|
};
|