0
Fork 0
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:
dragongoose 2023-04-16 16:09:07 -04:00
parent a7955614ff
commit 03474a422e
2 changed files with 11 additions and 7 deletions

View file

@ -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
View 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();
}
}