-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from outerbase/develop
deployment
- Loading branch information
Showing
17 changed files
with
312 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { HttpStatus } from "@/constants/http-status"; | ||
import { headers } from "next/headers"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export const runtime = "edge"; | ||
|
||
export async function POST(req: NextRequest) { | ||
// Get the account id and database id from header | ||
const endpoint = headers().get("x-starbase-url"); | ||
|
||
if (!endpoint) { | ||
return NextResponse.json( | ||
{ | ||
error: "Please provide account id or database id", | ||
}, | ||
{ status: HttpStatus.BAD_REQUEST } | ||
); | ||
} | ||
|
||
const authorizationHeader = headers().get("Authorization"); | ||
if (!authorizationHeader) { | ||
return NextResponse.json( | ||
{ | ||
error: "Please provide authorization header", | ||
}, | ||
{ status: HttpStatus.BAD_REQUEST } | ||
); | ||
} | ||
|
||
try { | ||
const url = `${endpoint.replace(/\/$/, "")}/query/raw`; | ||
|
||
const response: { errors: { message: string }[] } = await ( | ||
await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
Authorization: authorizationHeader, | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(await req.json()), | ||
}) | ||
).json(); | ||
|
||
if (response.errors && response.errors.length > 0) { | ||
return NextResponse.json( | ||
{ | ||
error: response.errors[0].message, | ||
}, | ||
{ status: HttpStatus.INTERNAL_SERVER_ERROR } | ||
); | ||
} | ||
|
||
return NextResponse.json(response); | ||
} catch (e) { | ||
return NextResponse.json( | ||
{ | ||
error: (e as Error).message, | ||
}, | ||
{ status: HttpStatus.BAD_REQUEST } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.