Skip to content

Handler API with data source #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
// You can access these endpoints at the following URL:
// https://starbasedb.YOUR-IDENTIFIER.workers.dev/api/your/path/here

export async function handleApiRequest(request: Request): Promise<Response> {
import { StarbaseContext } from '../handler'
import { DataSource } from '../types'

export async function handleApiRequest(
request: Request,
dataSource: DataSource
): Promise<Response> {
const url = new URL(request.url)

// EXAMPLE:
Expand Down
4 changes: 3 additions & 1 deletion src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ export class StarbaseDB {
)
}

this.app.all('/api/*', async (c) => handleApiRequest(c.req.raw))
this.app.all('/api/*', async (c) =>
handleApiRequest(c.req.raw, this.dataSource)
)

// Set up error handlers
this.app.notFound(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ export default {
events: [],
})

cdcPlugin.onEvent(({ action, schema, table, data }) => {
cdcPlugin.onEvent(async ({ action, schema, table, data }) => {
// Include change data capture code here
}, ctx)

cronPlugin.onEvent(({ name, cron_tab, payload }) => {
cronPlugin.onEvent(async ({ name, cron_tab, payload }) => {
// Include cron event code here
}, ctx)

Expand Down