mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-20 23:12:13 +00:00
routes regexp implemented with custom regexp
This commit is contained in:
parent
493b6c3d79
commit
4e02638e7c
1 changed files with 40 additions and 21 deletions
|
|
@ -1,25 +1,44 @@
|
||||||
const PathToRegexp = require('path-to-regexp');
|
|
||||||
|
|
||||||
const compilePath = (path, options) => {
|
|
||||||
const keys = [];
|
|
||||||
const regexp = PathToRegexp(path, keys, { ...options });
|
|
||||||
return {
|
|
||||||
regexp,
|
|
||||||
urlParamsNames: keys.map(({ name }) => name)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const routesRegexp = {
|
const routesRegexp = {
|
||||||
intro: compilePath('/intro'),
|
intro: {
|
||||||
board: compilePath('/'),
|
regexp: /^\/intro\/?$/i,
|
||||||
discover: compilePath('/discover/:type?/:catalog?'),
|
urlParamsNames: []
|
||||||
library: compilePath('/library/:sort?'),
|
},
|
||||||
calendar: compilePath('/calendar'),
|
board: {
|
||||||
search: compilePath('/search'),
|
regexp: /^\/?$/i,
|
||||||
detail: compilePath('/detail/:type/:id/:videoId?'),
|
urlParamsNames: []
|
||||||
addons: compilePath('/addons'),
|
},
|
||||||
settings: compilePath('/settings'),
|
discover: {
|
||||||
player: compilePath('/player')
|
regexp: /^\/discover(?:\/([^\/]*?))?(?:\/([^\/]*?))?\/?$/i,
|
||||||
|
urlParamsNames: ['type', 'catalog']
|
||||||
|
},
|
||||||
|
library: {
|
||||||
|
regexp: /^\/library(?:\/([^\/]*?))?\/?$/i,
|
||||||
|
urlParamsNames: ['sort']
|
||||||
|
},
|
||||||
|
calendar: {
|
||||||
|
regexp: /^\/calendar\/?$/i,
|
||||||
|
urlParamsNames: []
|
||||||
|
},
|
||||||
|
search: {
|
||||||
|
regexp: /^\/search\/?$/i,
|
||||||
|
urlParamsNames: []
|
||||||
|
},
|
||||||
|
detail: {
|
||||||
|
regexp: /^\/detail\/(?:([^\/]+?))\/(?:([^\/]+?))(?:\/([^\/]*?))?\/?$/i,
|
||||||
|
urlParamsNames: []
|
||||||
|
},
|
||||||
|
addons: {
|
||||||
|
regexp: /^\/addons\/?$/i,
|
||||||
|
urlParamsNames: []
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
regexp: /^\/settings\/?$/i,
|
||||||
|
urlParamsNames: []
|
||||||
|
},
|
||||||
|
player: {
|
||||||
|
regexp: /^\/player\/?$/i,
|
||||||
|
urlParamsNames: []
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = routesRegexp;
|
module.exports = routesRegexp;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue