1
1
/*
2
2
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
3
3
Copyright (C) 2023 Spacebar and Spacebar Contributors
4
-
4
+
5
5
This program is free software: you can redistribute it and/or modify
6
6
it under the terms of the GNU Affero General Public License as published
7
7
by the Free Software Foundation, either version 3 of the License, or
8
8
(at your option) any later version.
9
-
9
+
10
10
This program is distributed in the hope that it will be useful,
11
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
13
GNU Affero General Public License for more details.
14
-
14
+
15
15
You should have received a copy of the GNU Affero General Public License
16
16
along with this program. If not, see <https://www.gnu.org/licenses/>.
17
17
*/
@@ -22,7 +22,8 @@ import path from "path";
22
22
import avatarsRoute from "./routes/avatars" ;
23
23
import guildProfilesRoute from "./routes/guild-profiles" ;
24
24
import iconsRoute from "./routes/role-icons" ;
25
- import bodyParser from "body-parser" ;
25
+ import { CORS } from "../api/middlewares/CORS" ;
26
+ import { BodyParser } from "../api/middlewares/BodyParser" ;
26
27
27
28
export type CDNServerOptions = ServerOptions ;
28
29
@@ -38,24 +39,10 @@ export class CDNServer extends Server {
38
39
await Config . init ( ) ;
39
40
await Sentry . init ( this . app ) ;
40
41
41
- this . app . use ( ( req , res , next ) => {
42
- res . set ( "Access-Control-Allow-Origin" , "*" ) ;
43
- // TODO: use better CSP policy
44
- res . set (
45
- "Content-security-policy" ,
46
- "default-src * data: blob: filesystem: about: ws: wss: 'unsafe-inline' 'unsafe-eval'; script-src * data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src * data: blob: 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src * data: blob: ; style-src * data: blob: 'unsafe-inline'; font-src * data: blob: 'unsafe-inline';" ,
47
- ) ;
48
- res . set (
49
- "Access-Control-Allow-Headers" ,
50
- req . header ( "Access-Control-Request-Headers" ) || "*" ,
51
- ) ;
52
- res . set (
53
- "Access-Control-Allow-Methods" ,
54
- req . header ( "Access-Control-Request-Methods" ) || "*" ,
55
- ) ;
56
- next ( ) ;
57
- } ) ;
58
- this . app . use ( bodyParser . json ( { inflate : true , limit : "10mb" } ) ) ;
42
+ this . app . disable ( "x-powered-by" ) ;
43
+
44
+ this . app . use ( CORS ) ;
45
+ this . app . use ( BodyParser ( { inflate : true , limit : "10mb" } ) ) ;
59
46
60
47
await registerRoutes ( this , path . join ( __dirname , "routes/" ) ) ;
61
48
0 commit comments