mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2025-01-05 04:10:06 -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 { wsServer } from './routes/proxyRoute';
|
||||||
import compression from 'compression'
|
import compression from 'compression'
|
||||||
import { version } from './package.json';
|
import { version } from './package.json';
|
||||||
|
import { cors } from './util/cors';
|
||||||
|
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
const app: Express = express();
|
const app: Express = express();
|
||||||
const port = process.env.PORT
|
const port = process.env.PORT
|
||||||
|
|
||||||
app.all('/', function(req, res, next) {
|
app.use(cors())
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
|
||||||
res.header("Access-Control-Allow-Headers", "X-Requested-With");
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
app.use(compression({}))
|
app.use(compression({}))
|
||||||
app.use(routes)
|
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