mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +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 = {
|
||||
intro: compilePath('/intro'),
|
||||
board: compilePath('/'),
|
||||
discover: compilePath('/discover/:type?/:catalog?'),
|
||||
library: compilePath('/library/:sort?'),
|
||||
calendar: compilePath('/calendar'),
|
||||
search: compilePath('/search'),
|
||||
detail: compilePath('/detail/:type/:id/:videoId?'),
|
||||
addons: compilePath('/addons'),
|
||||
settings: compilePath('/settings'),
|
||||
player: compilePath('/player')
|
||||
intro: {
|
||||
regexp: /^\/intro\/?$/i,
|
||||
urlParamsNames: []
|
||||
},
|
||||
board: {
|
||||
regexp: /^\/?$/i,
|
||||
urlParamsNames: []
|
||||
},
|
||||
discover: {
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue