-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (69 loc) 路 2.04 KB
/
index.js
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
/**
* @file This file serves as the entry point for the SheTreks backend application.
* It imports necessary modules, initializes controllers and routers, implements middleware,
* and starts the application.
* @module index.js
*/
"use strict";
import { Hono } from "hono";
import { clerkMiddleware, getAuth } from "@hono/clerk-auth";
import { cors } from "hono/cors";
// importing DB
import db from "./db/models/index";
const {
users,
locations,
activities,
participants,
followings,
categories,
group_sizes,
notifications,
} = db;
//importing Controllers
import UsersController from "./controllers/usersController";
import LocationsController from "./controllers/locationsController";
import ActivitiesController from "./controllers/activitiesController";
//importing Routers
import UsersRouter from "./routers/usersRouter";
import LocationsRouter from "./routers/locationsRouter";
import ActivitiesRouter from "./routers/activitiesRouter";
//initializing Controllers
const usersController = new UsersController(
users,
locations,
followings,
notifications
);
const locationsController = new LocationsController(locations);
const activitiesController = new ActivitiesController(
activities,
categories,
group_sizes,
locations,
participants,
users
);
//initializing Routers
const usersRouter = new UsersRouter(usersController).route();
const locationsRouter = new LocationsRouter(locationsController).route();
const activitiesRouter = new ActivitiesRouter(activitiesController).route();
const PORT = process.env.PORT;
const app = new Hono();
//implement cors midddleware to allow all origins
app.use(cors());
//implementing clerk middleware
app.use(clerkMiddleware());
app.use(async (c, next) => {
const auth = getAuth(c);
if (!auth.userId) {
return c.json({ message: "You are unauthenticated" }, 401);
}
await next();
});
//implementing routers
app.route("/users", usersRouter);
app.route("/locations", locationsRouter);
app.route("/activities", activitiesRouter);
//starting app
export default { port: PORT, fetch: app.fetch };