summary refs log tree commit diff
path: root/src/api/routes.js
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-06-01 14:43:00 +0200
committerRory& <root@rory.gay>2025-06-01 14:43:00 +0200
commita3869af4c616da1f8af900594cbad2b829d7644a (patch)
tree67245749d32373b199be7714b30b529715ce4614 /src/api/routes.js
parentAdd alarm endpoints, basic budget routes, spend history (diff)
downloadnodejs-final-assignment-a3869af4c616da1f8af900594cbad2b829d7644a.tar.xz
Partial progress on generating http files
Diffstat (limited to 'src/api/routes.js')
-rw-r--r--src/api/routes.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/api/routes.js b/src/api/routes.js

index 09606f1..5151187 100644 --- a/src/api/routes.js +++ b/src/api/routes.js
@@ -1,6 +1,21 @@ import * as routes from './routes/index.js'; +function logHttpEntry(method, route, exampleBody) { + console.log('%', method, '{{baseUrl}}' + route, 'HTTP/1.1'); + if (exampleBody) { + console.log('%', 'Content-Type: application/json'); + console.log('% '); + console.log('%', exampleBody); + console.log('% '); + } + console.log('% '); + console.log('%', '###'); +} + export function registerRoutes(app) { + // http file header: + console.log('%', ''); + // app.get("/status", routes.statusRoute); let routeCount = 0; Object.values(routes).forEach(route => { @@ -16,19 +31,25 @@ export function registerRoutes(app) { app.get(route.route, route.onGetValidation, route.onGet); else app.get(route.route, route.onGet); routeCount++; + logHttpEntry('GET', route.route, route.exampleGetBody); } + if (route.onPost) { if (route.onPostValidation) app.post(route.route, route.onPostValidation, route.onPost); else app.post(route.route, route.onPost); routeCount++; + logHttpEntry('POST', route.route, route.examplePostBody); } + if (route.onPut) { if (route.onPutValidation) app.put(route.route, route.onPutValidation, route.onPut); else app.put(route.route, route.onPut); routeCount++; + logHttpEntry('PUT', route.route, route.examplePutBody); } + if (route.onDelete) { if (route.onDeleteValidation) app.delete( @@ -38,12 +59,15 @@ export function registerRoutes(app) { ); else app.delete(route.route, route.onDelete); routeCount++; + logHttpEntry('DELETE', route.route, route.exampleDeleteBody); } + if (route.onPatch) { if (route.onPatchValidation) app.patch(route.route, route.onPatchValidation, route.onPatch); else app.patch(route.route, route.onPatch); routeCount++; + logHttpEntry('PATCH', route.route, route.examplePatchBody); } }); console.log(`Registered ${routeCount} routes.`);