Skip to content

Commit

Permalink
added vercel proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Precious-Macaulay authored Nov 9, 2024
1 parent ff04d26 commit a5f5506
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions api/proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import httpProxy from 'http-proxy';
import dotenv from 'dotenv';

dotenv.config();

const proxy = httpProxy.createProxyServer({});
const BEARER_TOKEN = process.env.ASTRIA_API_KEY;

export default function handler(req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Authorization, Content-Type');

if (req.method === 'OPTIONS') {
return res.status(204).end();
}

req.headers['Authorization'] = `Bearer ${BEARER_TOKEN}`;

proxy.web(req, res, { target: 'https://api.astria.ai', changeOrigin: true }, (error) => {
console.error('Proxy error:', error);
res.status(500).end('Proxy error occurred.');
});
}

0 comments on commit a5f5506

Please sign in to comment.