Skip to content

Commit

Permalink
fix: Routes bug with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Feb 29, 2024
1 parent 6c9183a commit ace496d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/server/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function buildBaseApi(app: HttpServer) {
sendJson(res, json);
});

app.route(/\/api\/counters\/search\/(?<query>.*)/, 'GET', (req, res) => {
app.route(/^\/api\/counters\/search\/(?<query>.*)/, 'GET', (req, res) => {
try {
const query = decodeURI(req.params.query)
.replace(/[^a-z0-9A-Z]/, '')
Expand All @@ -61,7 +61,7 @@ export default function buildBaseApi(app: HttpServer) {
}
});

app.route(/\/api\/counters\/download\/(?<url>.*)/, 'GET', (req, res) => {
app.route(/^\/api\/counters\/download\/(?<url>.*)/, 'GET', (req, res) => {
const folderName = req.query.name;
if (!folderName) {
return sendJson(res, {
Expand Down Expand Up @@ -121,7 +121,7 @@ export default function buildBaseApi(app: HttpServer) {
}
});

app.route(/\/api\/counters\/open\/(?<name>.*)/, 'GET', (req, res) => {
app.route(/^\/api\/counters\/open\/(?<name>.*)/, 'GET', (req, res) => {
try {
const folderName = req.params.name;
if (!folderName) {
Expand Down Expand Up @@ -166,7 +166,7 @@ export default function buildBaseApi(app: HttpServer) {
}
});

app.route(/\/api\/counters\/delete\/(?<name>.*)/, 'GET', (req, res) => {
app.route(/^\/api\/counters\/delete\/(?<name>.*)/, 'GET', (req, res) => {
try {
const folderName = req.params.name;
if (!folderName) {
Expand Down Expand Up @@ -222,7 +222,7 @@ export default function buildBaseApi(app: HttpServer) {
});
});

app.route(/\/images\/(?<filePath>.*)/, 'GET', (req, res) => {
app.route(/^\/images\/(?<filePath>.*)/, 'GET', (req, res) => {
fs.readFile(
path.join(pkgAssetsPath, 'images', req.params.filePath),
(err, content) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/router/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function buildV1Api({
}
});

app.route(/\/Songs\/(?<filePath>.*)/, 'GET', (req, res) => {
app.route(/^\/Songs\/(?<filePath>.*)/, 'GET', (req, res) => {
const url = req.pathname || '/';

const osuInstances: any = Object.values(
Expand Down
4 changes: 2 additions & 2 deletions packages/server/router/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function buildV2Api({
sendJson(res, json);
});

app.route(/\/files\/beatmap\/(?<filePath>.*)/, 'GET', (req, res) => {
app.route(/^\/files\/beatmap\/(?<filePath>.*)/, 'GET', (req, res) => {
const url = req.pathname || '/';

const osuInstances: any = Object.values(
Expand All @@ -87,7 +87,7 @@ export default function buildV2Api({
});
});

app.route(/\/files\/skin\/(?<filePath>.*)/, 'GET', (req, res) => {
app.route(/^\/files\/skin\/(?<filePath>.*)/, 'GET', (req, res) => {
const url = req.pathname || '/';

const osuInstances: any = Object.values(
Expand Down

0 comments on commit ace496d

Please sign in to comment.