-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support cloudflare worker analytic engine
- Loading branch information
Showing
8 changed files
with
348 additions
and
251 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { HttpStatus } from "@/constants/http-status"; | ||
import { headers } from "next/headers"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function POST(req: NextRequest) { | ||
const headerStore = await headers(); | ||
|
||
// Get the account id and database id from header | ||
const accountId = headerStore.get("x-account-id"); | ||
|
||
if (!accountId) { | ||
return NextResponse.json( | ||
{ | ||
error: "Please provide account id or database id", | ||
}, | ||
{ status: HttpStatus.BAD_REQUEST } | ||
); | ||
} | ||
|
||
const authorizationHeader = headerStore.get("Authorization"); | ||
if (!authorizationHeader) { | ||
return NextResponse.json( | ||
{ | ||
error: "Please provide authorization header", | ||
}, | ||
{ status: HttpStatus.BAD_REQUEST } | ||
); | ||
} | ||
|
||
try { | ||
const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/analytics_engine/sql`; | ||
|
||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
Authorization: authorizationHeader, | ||
"Content-Type": "text/plain", | ||
}, | ||
body: await req.text(), | ||
}); | ||
|
||
if (!response.ok) { | ||
return NextResponse.json( | ||
{ | ||
error: await response.text(), | ||
}, | ||
{ status: response.status } | ||
); | ||
} | ||
|
||
return NextResponse.json(await response.json()); | ||
} catch (e) { | ||
return NextResponse.json( | ||
{ | ||
error: (e as Error).message, | ||
}, | ||
{ status: HttpStatus.BAD_REQUEST } | ||
); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/components/connection-config-editor/template/cloudflare-wae.tsx
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,49 @@ | ||
import { ConnectionTemplateList } from "@/app/(outerbase)/base-template"; | ||
import { CommonConnectionConfigTemplate } from ".."; | ||
|
||
const template: CommonConnectionConfigTemplate = [ | ||
{ | ||
columns: [ | ||
{ | ||
name: "username", | ||
label: "Account ID", | ||
type: "text", | ||
required: true, | ||
placeholder: "Account ID", | ||
}, | ||
], | ||
}, | ||
{ | ||
columns: [ | ||
{ | ||
name: "token", | ||
label: "API Token", | ||
type: "textarea", | ||
required: true, | ||
placeholder: "API Token", | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
export const CloudflareWAEConnectionTemplate: ConnectionTemplateList = { | ||
localFrom: (value) => { | ||
return { | ||
name: value.name, | ||
database: value.database, | ||
token: value.token, | ||
username: value.username, | ||
}; | ||
}, | ||
localTo: (value) => { | ||
return { | ||
name: value.name, | ||
driver: "cloudflare-wae", | ||
database: value.database, | ||
token: value.token, | ||
username: value.username, | ||
}; | ||
}, | ||
template, | ||
instruction: <div></div>, | ||
}; |
Oops, something went wrong.