summary refs log tree commit diff
path: root/src/api/routes.js
blob: 0da8be9603c098e5592008fdbf52b8ec372ffff1 (plain) (blame)
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
import * as routes from './routes/index.js';

export function registerRoutes(app) {
    // app.get("/status", routes.statusRoute);
    let routeCount = 0;
    Object.values(routes).forEach(route => {
        console.log('Registering route:', route);
        if (!route.route)
            throw new Error(
                "Route definition is missing 'route' property: " +
                    JSON.stringify(route)
            );

        if (route.onGet) {
            app.get(route.route, route.onGet);
            routeCount++;
        }
        if (route.onPost) {
            app.post(route.route, route.onPost);
            routeCount++;
        }
        if (route.onPut) {
            app.put(route.route, route.onPut);
            routeCount++;
        }
        if (route.onDelete) {
            app.put(route.route, route.onDelete);
            routeCount++;
        }
        if (route.onPatch) {
            app.patch(route.route, route.onPatch);
            routeCount++;
        }
    });
    console.log(`Registered ${routeCount} routes.`);
}