Files
VTHacks-12/server/APIRoute.js
2024-09-14 11:04:06 -04:00

37 lines
824 B
JavaScript

import express from 'express';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
export default class APIRoute {
constructor(path = '/') {
this.path = "/api" + path;
this.router = express.Router();
this.router.use(cookieParser());
this.router.use(bodyParser.json());
this.router.use(bodyParser.urlencoded({ extended: true }));
this.router.get("/", this.get);
this.router.post("/", this.post);
}
addSubRoute(name, method, callback) {
this.router[method](name, callback);
}
async get(req, res) {
res.send('GET request');
}
async post(req, res) {
res.send('POST request');
}
getPath() {
return this.path;
}
getRouter() {
return this.router;
}
}