-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
110 lines (100 loc) · 3.07 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { serve } from '@hono/node-server';
import { swaggerUI } from '@hono/swagger-ui';
import { OpenAPIHono } from '@hono/zod-openapi';
import type { Context } from 'hono';
import { compress } from 'hono/compress';
import { cors } from 'hono/cors';
import { HTTPException } from 'hono/http-exception';
import { logger } from 'hono/logger';
import { prettyJSON } from 'hono/pretty-json';
import { secureHeaders } from 'hono/secure-headers';
import { activities } from './handlers/activities.js';
import { assemblies } from './handlers/assemblies.js';
import { auth } from './handlers/auth.js';
import { blog } from './handlers/blog.js';
import { edm } from './handlers/edm.js';
import { health } from './handlers/health.js';
import { location } from './handlers/location.js';
import { materials } from './handlers/materials.js';
import { messages } from './handlers/messages.js';
import { reasons } from './handlers/reasons.js';
import { reports } from './handlers/reports.js';
import { sports } from './handlers/sports.js';
import { stats } from './handlers/stats.js';
import { stripe } from './handlers/stripe.js';
import { tasks } from './handlers/tasks.js';
import { activities_teams } from './handlers/teams.js';
import { tournaments } from './handlers/tournaments.js';
import { users } from './handlers/users.js';
import { polls } from './handlers/votes.js';
const app = new OpenAPIHono();
if (!process.env.CI === true) {
app.use('*', logger());
}
app.use('*', prettyJSON());
app.use('*', secureHeaders());
app.use('*', compress());
app.use(
'*',
cors({
origin: '*',
allowHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
allowMethods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
}),
);
app.get('/', (c) => c.text('Athlonix API!', 200));
app.onError((err, c) => {
if (err instanceof HTTPException) {
return c.json({ error: err.message }, err.status || 500);
}
return c.json({ error: 'Internal server error' }, 500);
});
app.route('/', health);
app.route('/auth', auth);
app.route('/', users);
app.route('/', activities);
app.route('/', sports);
app.route('/', location);
app.route('/', polls);
app.route('/', blog);
app.route('/', reasons);
app.route('/', reports);
app.route('/', tournaments);
app.route('/', activities_teams);
app.route('/', stripe);
app.route('/', assemblies);
app.route('/', tasks);
app.route('/', edm);
app.route('/', stats);
app.route('/', materials);
app.route('/', messages);
app.doc('/doc', (c: Context) => ({
openapi: '3.0.0',
info: {
version: '1.0.0',
title: 'Athlonix API',
},
servers: [
{
url: new URL(c.req.url).origin,
description: 'Development server',
},
{
url: 'https://athlonix-api.jayllyz.fr',
description: 'Production server',
},
],
}));
app.openAPIRegistry.registerComponent('securitySchemes', 'Bearer', {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
});
app.get('/ui', swaggerUI({ url: '/doc' }));
const port = Number(process.env.PORT || 3101);
console.info(`Server is running on port ${port}`);
serve({
fetch: app.fetch,
port,
});
export default app;