internet-programming/lab3/node_modules/json-server/lib/server/rewriter.js

14 lines
338 B
JavaScript
Raw Normal View History

2023-11-02 02:38:40 +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;
};