Skip to content

Commit

Permalink
fix: cors are broken (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
KotRikD authored Dec 20, 2023
1 parent 7e11723 commit 77f4e85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/tosu/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const buildFastifyApp = async (instanceManager: InstanceManager) => {
req.instanceManager = instanceManager;
});
// apply cors rules to request
app.addHook('onRequest', async (req, reply) => {
app.addHook('onRequest', async (_, reply) => {
reply.header('Access-Control-Allow-Origin', '*');
reply.header(
'Access-Control-Allow-Headers',
Expand Down
9 changes: 9 additions & 0 deletions packages/tosu/src/api/router/gosu/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ export const buildV1Router = (app: FastifyInstance) => {
const mapPath = parsedURL.pathname.replace('/Songs', '');

reply.hijack();
reply.raw.setHeader('Access-Control-Allow-Origin', '*');
reply.raw.setHeader(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
);
reply.raw.setHeader(
'Access-Control-Allow-Methods',
'POST, GET, PUT, DELETE, OPTIONS'
);
send(req, mapPath, { root: settings.songsFolder }).pipe(reply.raw);
});
};
1 change: 0 additions & 1 deletion packages/tosu/src/api/utils/buildResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'path';
import { DataRepo } from '@/entities/DataRepoList';
import { LeaderboardPlayer as MemoryLeaderboardPlayer } from '@/entities/GamePlayData/Leaderboard';
import { InstanceManager } from '@/objects/instanceManager/instanceManager';
import { OsuInstance } from '@/objects/instanceManager/osuInstance';
import { fixDecimals } from '@/utils/fixDecimals';
import { getOsuModsString } from '@/utils/osuMods';

Expand Down

0 comments on commit 77f4e85

Please sign in to comment.