enable cors

merge pull request #100 from jojobii-arks/jojobii-arks/98-fix-cors
This commit is contained in:
wukko 2023-03-29 18:25:46 +06:00 committed by GitHub
commit 6e01026894
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,6 +27,7 @@ const branch = getCurrentBranch();
const app = express();
app.disable('x-powered-by');
app.use('/api/:type', cors())
if (fs.existsSync('./.env') && process.env.selfURL && process.env.streamSalt && process.env.port) {
const apiLimiter = rateLimit({
@ -80,7 +81,7 @@ if (fs.existsSync('./.env') && process.env.selfURL && process.env.streamSalt &&
}
}));
app.post('/api/json', cors({ origin: process.env.selfURL, optionsSuccessStatus: 200 }), async (req, res) => {
app.post('/api/json', async (req, res) => {
try {
let ip = sha256(req.header('x-forwarded-for') ? req.header('x-forwarded-for') : req.ip.replace('::ffff:', ''), process.env.streamSalt);
let lang = languageCode(req);
@ -104,7 +105,7 @@ if (fs.existsSync('./.env') && process.env.selfURL && process.env.streamSalt &&
}
});
app.get('/api/:type', cors({ origin: process.env.selfURL, optionsSuccessStatus: 200 }), (req, res) => {
app.get('/api/:type', (req, res) => {
try {
let ip = sha256(req.header('x-forwarded-for') ? req.header('x-forwarded-for') : req.ip.replace('::ffff:', ''), process.env.streamSalt);
switch (req.params.type) {