InternetProgramming/Lab3/node_modules/json-server/lib/server/rewriter.js

14 lines
338 B
JavaScript
Raw Normal View History

2023-12-15 14:42:22 +04:00
"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;
};