Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
support multi search parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
antergone committed Dec 18, 2023
1 parent b8d0c2d commit a6db0ee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const config = {
async rewrites() {
return [
{
source: "/:path*",
source: "/:_path*",
"has": [
{
"type": "query",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"private": true,
"scripts": {
"next": "next",
"build": "next build"
"build": "next build",
"dev": "PORT=4000 next dev"
},
"dependencies": {
"next": "canary",
Expand Down
8 changes: 7 additions & 1 deletion src/handle-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ export default async function handleRequest(request: NextRequest & { nextUrl?: U
// -d '{ "prompt": { "text": "Write a story about a magic backpack"} }' \
// "https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key={YOUR_KEY}"

const url = new URL(pathname + `?key=${searchParams.get('key')}`, "https://generativelanguage.googleapis.com").href;
const url = new URL(pathname, "https://generativelanguage.googleapis.com");
searchParams.delete("_path");

searchParams.forEach((value, key) => {
url.searchParams.append(key, value);
});

const headers = pickHeaders(request.headers, ["content-type"]);

const response = await fetch(url, {
Expand Down

0 comments on commit a6db0ee

Please sign in to comment.