mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2025-01-03 11:20:08 -05:00
Add better cors implementation
This commit is contained in:
parent
a7955614ff
commit
03474a422e
2 changed files with 11 additions and 7 deletions
9
index.ts
9
index.ts
|
@ -5,19 +5,14 @@ import { errorHandler } from './util/errorHandler'
|
|||
import { wsServer } from './routes/proxyRoute';
|
||||
import compression from 'compression'
|
||||
import { version } from './package.json';
|
||||
import { cors } from './util/cors';
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const app: Express = express();
|
||||
const port = process.env.PORT
|
||||
|
||||
app.all('/', function(req, res, next) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "X-Requested-With");
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
app.use(cors())
|
||||
app.use(compression({}))
|
||||
app.use(routes)
|
||||
|
||||
|
|
9
util/cors.ts
Normal file
9
util/cors.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { NextFunction, Request, Response } from "express";
|
||||
|
||||
export const cors = () => {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "X-Requested-With");
|
||||
next();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue