-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathindex.ts
97 lines (80 loc) · 2.21 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
import { Hono } from "hono";
import { cors } from "hono/cors";
import { logger } from "hono/logger";
import { prettyJSON } from "hono/pretty-json";
import { config } from "./lib/config";
import { camelCaseMiddleware, rateLimitMiddleware } from "./lib/middleware";
import {
album,
artist,
get,
home,
modules,
ping,
playlist,
radio,
search,
show,
song,
} from "./routes";
import { CustomResponse } from "./types/response";
const app = new Hono({ strict: false }); // match routes w/ or w/o trailing slash
/* -----------------------------------------------------------------------------------------------
* middlewares
* -----------------------------------------------------------------------------------------------*/
app.use(
"*",
cors(),
prettyJSON(),
logger(),
rateLimitMiddleware(),
camelCaseMiddleware()
);
/* -----------------------------------------------------------------------------------------------
* routes
* -----------------------------------------------------------------------------------------------*/
/* home */
app.route("/", home);
/* modules */
app.route("/modules", modules);
/* details & recommendations */
app.route("/song", song);
app.route("/album", album);
app.route("/playlist", playlist);
app.route("/artist", artist);
/* search */
app.route("/search", search);
/* show */
app.route("/show", show);
/* get */
app.route("/get", get);
/* radio */
app.route("/radio", radio);
/* test route to check if the server is up and running */
app.route("/ping", ping);
/* 404 */
app.notFound((c) => {
c.status(404);
return c.json({
status: "Failed",
message: `Requested route not found, please check the documentation at ${config.urls.docsUrl}`,
});
});
/* -----------------------------------------------------------------------------------------------
* error handler
* -----------------------------------------------------------------------------------------------*/
app.onError((err, c) => {
const response: CustomResponse = {
status: "Failed",
message: `❌ ${err.message}`,
data: null,
};
c.status(400);
return c.json(response);
});
const server = {
port: +(process.env.PORT ?? 3000),
fetch: app.fetch,
};
export { app };
export default server;