Skip to content

Commit 1a87ac0

Browse files
authored
Merge pull request #586 from framer/huntercaron/mkcert-secure-ws
Use secure websockets with mkcert
2 parents 81b914b + a222272 commit 1a87ac0

File tree

6 files changed

+1071
-23
lines changed

6 files changed

+1071
-23
lines changed

packages/code-link-cli/src/controller.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { pluralize, shortProjectHash } from "@code-link/shared"
1010
import fs from "fs/promises"
1111
import path from "path"
1212
import type { WebSocket } from "ws"
13+
import { CERT_DIR, getOrCreateCerts } from "./helpers/certs.ts"
1314
import { initConnection, sendMessage } from "./helpers/connection.ts"
1415
import {
1516
autoResolveConflicts,
@@ -1063,8 +1064,20 @@ export async function start(config: Config): Promise<void> {
10631064
}
10641065
}
10651066

1066-
// WebSocket Connection
1067-
const connection = await initConnection(config.port)
1067+
// TLS certificates for WSS — required for browser connection
1068+
const certs = await getOrCreateCerts()
1069+
if (!certs) {
1070+
error("Failed to generate TLS certificates. The Framer plugin requires a secure (wss://) connection.")
1071+
info("")
1072+
info("To fix this:")
1073+
info(" 1. Re-run this command — certificate generation is often a one-time issue")
1074+
info(` 2. Manually delete "${String(CERT_DIR)}" and try again`)
1075+
info("")
1076+
throw new Error("TLS certificate generation failed")
1077+
}
1078+
1079+
// WebSocket Connection (always WSS)
1080+
const connection = await initConnection(config.port, certs)
10681081

10691082
// Handle initial handshake
10701083
connection.on("handshake", (client: WebSocket, message) => {

0 commit comments

Comments
 (0)