Skip to content

Commit

Permalink
fixed the CORS issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fatwang2 committed Apr 25, 2024
1 parent ecc94f8 commit 6f3d8e4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,23 @@ switch (botType) {
default:
throw new Error('Invalid bot type in the environment variable.');
}
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
Binary file added pictures/usage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ pnpm start
```

## Usage
1. OpenAI Clients

![botgem](pictures/usage.png)

2. Code

```JavaScript
const response = await fetch('http://localhost:3000/v1/chat/completions', {
method: 'POST',
Expand Down

0 comments on commit 6f3d8e4

Please sign in to comment.