51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import GitHub from '@auth/core/providers/github';
|
|
import { authHandler, initAuthConfig, verifyAuth } from '@hono/auth-js';
|
|
import { serve } from '@hono/node-server';
|
|
import { serveStatic } from '@hono/node-server/serve-static';
|
|
import { Hono } from 'hono';
|
|
import packageRoutes from './server/routes/packages';
|
|
import productRoutes from './server/routes/products';
|
|
import subscriptionRoutes from './server/routes/subscriptions';
|
|
const app = new Hono()
|
|
|
|
// Auth middleware
|
|
app.use(
|
|
'*',
|
|
initAuthConfig((c) => ({
|
|
secret: process.env.AUTH_SECRET,
|
|
providers: [
|
|
GitHub({
|
|
clientId: process.env.GITHUB_ID,
|
|
clientSecret: process.env.GITHUB_SECRET,
|
|
}),
|
|
],
|
|
}))
|
|
)
|
|
|
|
// Static files
|
|
app.use('/static/*', serveStatic({root: 'src/public'}));
|
|
|
|
// Auth routes
|
|
app.use('/api/auth/*', authHandler())
|
|
|
|
// Protected routes
|
|
app.use('/api/*', verifyAuth())
|
|
|
|
// Routes
|
|
app.route('/api/packages', packageRoutes)
|
|
app.route('/api/subscriptions', subscriptionRoutes)
|
|
app.route('/api/products', productRoutes)
|
|
|
|
app.get('/', (c) => {
|
|
return c.text('Hello Hono!')
|
|
})
|
|
|
|
|
|
app.get('*', (c) => {
|
|
return c.notFound()
|
|
})
|
|
|
|
const port = process.env.PORT || 3000;
|
|
|
|
serve({ fetch: app.fetch, port: Number(port) })
|