Skip to content

Commit

Permalink
fixed cors issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fatwang2 committed Apr 24, 2024
1 parent adccb2d commit f183a01
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,23 @@ const app = express();
app.use(bodyParser.json());
const default_bot_id = process.env.BOT_ID || "";
const botConfig = process.env.BOT_CONFIG ? JSON.parse(process.env.BOT_CONFIG) : {};
var corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers":
"DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization",
"Access-Control-Max-Age": "86400",
};

app.use((req, res, next) => {
res.set(corsHeaders);
if (req.method === 'OPTIONS') {
return res.status(204).end();
}
console.log('Request Method:', req.method);
console.log('Request Path:', req.path);
next();
});
app.get("/", (req, res) => {
res.send(`
<html>
Expand Down

0 comments on commit f183a01

Please sign in to comment.