mirror of
https://github.com/sergeyyarkov/node-docker-example.git
synced 2026-10-11 02:09:22 +03:00
31 lines
510 B
JavaScript
31 lines
510 B
JavaScript
import http from 'node:http';
|
|
|
|
class Router {
|
|
constructor() {
|
|
/**
|
|
* Store the current list of routes for out API
|
|
*/
|
|
this.routes = {};
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {http.ClientRequest} req
|
|
* @param {http.ServerResponse} res
|
|
* @returns
|
|
*/
|
|
call(req, res) {
|
|
if (this.routes.hasOwnProperty(req.url)) {
|
|
this.routes[req.url](req, res);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
define(url, handler) {
|
|
this.routes[url] = handler;
|
|
}
|
|
}
|
|
|
|
export default new Router();
|