chore: add pnpm monorepo skeleton with core contracts
Shared notebook model (types.ts), HTTP/WebSocket protocol (protocol.ts) and core function signatures (stubs) so core, server and web can be built in parallel. Minimal Fastify server with a health route and test.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@shellbook/server",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "tsx watch src/main.ts",
|
||||
"build": "tsc -p tsconfig.json --noEmit",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||
"test": "vitest run --passWithNoTests"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastify/websocket": "^11.0.1",
|
||||
"@shellbook/core": "workspace:*",
|
||||
"fastify": "^5.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tsx": "^4.19.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import Fastify, { type FastifyInstance } from "fastify";
|
||||
import websocket from "@fastify/websocket";
|
||||
|
||||
export interface AppOptions {
|
||||
logger?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Fastify app. Feature areas live in their own folders and are
|
||||
* registered here as Fastify plugins, one line each:
|
||||
* M2 src/workspace/ (notebooks, hosts.yaml), src/ssh/, src/runs/ (queue, audit, artifacts, /api/events)
|
||||
* M4 src/terminal/ (node-pty + tmux, /api/terminal), src/watch/ (file.changed events)
|
||||
* M5 src/auth/ (login, persistent session secret)
|
||||
*/
|
||||
export async function buildApp(options: AppOptions = {}): Promise<FastifyInstance> {
|
||||
const app = Fastify({ logger: options.logger ?? false });
|
||||
await app.register(websocket);
|
||||
|
||||
app.get("/api/health", async () => ({ ok: true }));
|
||||
|
||||
return app;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { buildApp } from "./app";
|
||||
|
||||
const host = process.env.SHELLBOOK_HOST ?? "127.0.0.1";
|
||||
const port = Number(process.env.SHELLBOOK_PORT ?? 8080);
|
||||
|
||||
const app = await buildApp({ logger: true });
|
||||
await app.listen({ host, port });
|
||||
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildApp } from "../src/app";
|
||||
|
||||
describe("health", () => {
|
||||
it("answers on /api/health", async () => {
|
||||
const app = await buildApp();
|
||||
const res = await app.inject({ method: "GET", url: "/api/health" });
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.json()).toEqual({ ok: true });
|
||||
await app.close();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["src", "test"]
|
||||
}
|
||||
Reference in New Issue
Block a user