Skip to content

Commit

Permalink
Algolia search proxy endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
calebjacob committed Aug 16, 2023
1 parent f880c94 commit 3a11a6f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/pages/api/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { NextApiRequest, NextApiResponse } from 'next';

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
try {
if (!process.env.ALGOLIA_ENDPOINT || !process.env.ALGOLIA_API_KEY || !process.env.ALGOLIA_APP_ID) {
throw new Error('Invalid algolia search environment variables');
}

const request = await fetch(process.env.ALGOLIA_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Algolia-Api-Key': process.env.ALGOLIA_API_KEY,
'X-Algolia-Application-Id': process.env.ALGOLIA_APP_ID,
},
body: JSON.stringify(req.body),
});
const data = await request.json();
res.status(request.status).json(data);
} catch (error: any) {
res.status(500).json({
message: error?.message || 'Unknown error',
});
}
};

export default handler;

0 comments on commit 3a11a6f

Please sign in to comment.