Skip to content
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
18 changes: 18 additions & 0 deletions packages/miniflare/src/plugins/core/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ExternalServer,
HttpOptions_Style,
TlsOptions_Version,
DatabaseServer,
} from "../../runtime";
import type { Awaitable } from "../../workers";
import type * as http from "node:http";
Expand Down Expand Up @@ -80,6 +81,22 @@ export const ExternalServerSchema = z.intersection(
// just ends up pinned at 100% CPU. Probably unbounded recursion? I guess this
// type is too complex? Something to investigate... :thinking_face:

export const DatabaseServerSchema = z.intersection(
z.object({
address: z.string(), // address should be required
scheme: z.string(),
sslmode: z.string(),
}),
z.object({
tcp: z.optional(
z.object({
tlsOptions: TlsOptionsSchema.optional(),
certificateHost: z.ostring(),
}),
)
}),
) as z.ZodType<DatabaseServer>;

const DiskDirectorySchema = z.object({
path: z.string(), // path should be required
writable: z.oboolean(),
Expand Down Expand Up @@ -112,5 +129,6 @@ export const ServiceDesignatorSchema = z.union([
z.object({ external: ExternalServerSchema }),
z.object({ disk: DiskDirectorySchema }),
z.object({ node: CustomNodeServiceSchema }),
z.object({ database: DatabaseServerSchema }),
CustomFetchServiceSchema,
]);
36 changes: 29 additions & 7 deletions packages/miniflare/src/plugins/hyperdrive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,35 @@
},
async getServices({ options }) {
return Object.entries(options.hyperdrives ?? {}).map<Service>(
([name, url]) => ({
name: `${HYPERDRIVE_PLUGIN_NAME}:${name}`,
external: {
address: `${url.hostname}:${getPort(url)}`,
tcp: {},
},
})
([name, url]) => {
const scheme = url.protocol.replace(":", "");
var sslmode = url.searchParams.get("sslmode");

Check failure on line 122 in packages/miniflare/src/plugins/hyperdrive/index.ts

View workflow job for this annotation

GitHub Actions / Checks

Unexpected var, use let or const instead
if(!sslmode && scheme == "mysql") {
// override mysql ssl-mode to match expected sslmodes in workerd
sslmode = url.searchParams.get("ssl-mode");
if(sslmode?.toLowerCase() == "required") {
sslmode = "require";
} else if(!sslmode || sslmode?.toLowerCase() == "preferred") {
sslmode = "prefer";
}
}
if(!sslmode) {
sslmode = "prefer";
}
return {
name: `${HYPERDRIVE_PLUGIN_NAME}:${name}`,
database: {
address: `${url.hostname}:${getPort(url)}`,
scheme: scheme,
sslmode: sslmode,
tcp: {
tlsOptions: {
trustBrowserCas: true,
},
},
},
}
}
);
},
};
Loading
Loading