Skip to content

hyperdrive not working #1044

@xucongyong

Description

@xucongyong

https://hyperdrive-test-dbt.pages.dev/api/test-hyperdrive

error: {"success":false,"error":"Uncaught TypeError: Failed to establish the WebSocket connection: expected server to reply with HTTP status code 101 (switching protocols), but received 530 instead."}

I can connect to the database normally, but I can't connect via Hyperdrive. How should I fix this?

code:

import { Client } from "pg";

export default {
async fetch(request, env, ctx) {
// Hyperdrive provides a unique generated connection string to connect to
// your database via Hyperdrive that can be used with your existing tools
const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
await client.connect();

try {
  // Sample SQL query
  const result = await client.query("SELECT * FROM pg_tables");

  return Response.json({result: result.rows});
} catch (e) {
  return Response.json({ error: e instanceof Error ? e.message : e }, { status: 500 });
}

},
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions