InternetProgramming/Lab3/node_modules/json-server/lib/server/rewriter.js
2023-12-15 14:42:22 +04:00

14 lines
338 B
JavaScript

"use strict";
const express = require('express');
const rewrite = require('express-urlrewrite');
module.exports = routes => {
const router = express.Router();
router.get('/__rules', (req, res) => {
res.json(routes);
});
Object.keys(routes).forEach(key => {
router.use(rewrite(key, routes[key]));
});
return router;
};