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
8 changes: 5 additions & 3 deletions lib/dev/DevServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
FileUpdatedEvent,
} from "lib/file-server/FileServerEvent"
import type { FileServerRoutes } from "lib/file-server/FileServerRoutes"
import { loadProjectConfig } from "lib/project-config"
import { loadRuntimeProjectConfig } from "lib/project-config"
import { EventsWatcher } from "lib/server/EventsWatcher"
import { createHttpServer } from "lib/server/createHttpServer"
import { addPackage } from "lib/shared/add-package"
Expand Down Expand Up @@ -86,14 +86,16 @@ export class DevServer {
this.componentFilePath = componentFilePath
this.projectDir = projectDir ?? path.dirname(componentFilePath)
this.kicadPcm = kicadPcm ?? false
const projectConfig = loadProjectConfig(this.projectDir)
this.ignoredFiles = projectConfig?.ignoredFiles ?? []
this.ignoredFiles = []
this.fsKy = ky.create({
prefixUrl: `http://localhost:${port}`,
}) as any
}

async start() {
const projectConfig = await loadRuntimeProjectConfig(this.projectDir)
this.ignoredFiles = projectConfig?.ignoredFiles ?? []

const { server } = await createHttpServer({
port: this.port,
defaultMainComponentPath: path.relative(
Expand Down
22 changes: 22 additions & 0 deletions lib/server/createHttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import pkg from "../../package.json"
// @ts-ignore
import winterspecBundle from "@tscircuit/file-server/dist/bundle.js"
import { getIndex } from "../site/getIndex"
import {
createDevRuntimeConfigApi,
handleDevRuntimeConfigRequest,
} from "./dev-runtime-config"
import { createKicadPcmProxy } from "./kicad-pcm-proxy"

export const createHttpServer = async ({
Expand All @@ -26,6 +30,9 @@ export const createHttpServer = async ({
entryFile?: string
}) => {
const fileServerHandler = getNodeHandler(winterspecBundle as any, {})
const runtimeConfigApi = projectDir
? createDevRuntimeConfigApi({ projectDir })
: null

// Create PCM proxy if enabled
const pcmProxy =
Expand All @@ -37,6 +44,20 @@ export const createHttpServer = async ({
const requestHost = req.headers.host ?? `localhost:${port}`
const url = new URL(req.url!, `http://${requestHost}`)

if (
runtimeConfigApi &&
(url.pathname === "/api/dev/runtime-config" ||
url.pathname === "/api/dev/runtime-config/rpc")
) {
const handled = await handleDevRuntimeConfigRequest({
req,
res,
url,
runtimeConfigApi,
})
if (handled) return
}

if (
url.pathname === "/api/files/upsert-multipart" &&
req.method === "POST"
Expand Down Expand Up @@ -142,6 +163,7 @@ export const createHttpServer = async ({
const html = await getIndex(
defaultMainComponentPath,
fileServerApiBaseUrl,
`${fileServerApiBaseUrl}/dev/runtime-config`,
)
res.writeHead(200, { "Content-Type": "text/html" })
res.end(html)
Expand Down
Loading
Loading