feat(hq): app skeleton with health endpoint (HQ-1 task 1)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>feat/client-detail-redesign
parent
5c3c13c9d3
commit
d17726941f
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "@sims/hq",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "node build-server.mjs",
|
||||
"start": "npm run build && node dist/server.cjs",
|
||||
"typecheck": "tsc -p tsconfig.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sims/auth": "*",
|
||||
"@sims/billing-engine": "*",
|
||||
"@sims/domain": "*",
|
||||
"better-sqlite3": "^11.7.0",
|
||||
"express": "^4.21.0",
|
||||
"puppeteer": "^23.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/better-sqlite3": "^7.6.11",
|
||||
"@types/express": "^4.17.21",
|
||||
"esbuild": "^0.25.0",
|
||||
"tsx": "^4.19.0"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
import { Router } from 'express'
|
||||
import type { DB } from './db'
|
||||
|
||||
export function apiRouter(_db: DB | null): Router {
|
||||
const r = Router()
|
||||
r.get('/health', (_req, res) => {
|
||||
res.json({ ok: true, service: 'sims-hq', version: '0.1.0' })
|
||||
})
|
||||
return r
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
import express from 'express'
|
||||
import type http from 'node:http'
|
||||
import { apiRouter } from './api'
|
||||
|
||||
export function startServer(port: number): http.Server {
|
||||
const app = express()
|
||||
app.use(express.json({ limit: '2mb' }))
|
||||
app.use('/api', apiRouter(null))
|
||||
return app.listen(port)
|
||||
}
|
||||
|
||||
// Direct launch (bundled dist/server.cjs); vitest imports startServer instead.
|
||||
if (process.argv[1]?.endsWith('server.cjs') || process.argv[1]?.endsWith('server.ts')) {
|
||||
const PORT = Number(process.env['HQ_PORT'] ?? 5182)
|
||||
startServer(PORT)
|
||||
console.log(`SiMS HQ console on http://localhost:${PORT}`)
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
import { describe, it, expect, afterAll } from 'vitest'
|
||||
import { startServer } from '../src/server'
|
||||
|
||||
const server = startServer(0)
|
||||
const base = () => `http://localhost:${(server.address() as { port: number }).port}`
|
||||
|
||||
describe('hq health', () => {
|
||||
afterAll(() => server.close())
|
||||
it('answers /api/health', async () => {
|
||||
const res = await fetch(`${base()}/api/health`)
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.json()).toMatchObject({ ok: true, service: 'sims-hq' })
|
||||
})
|
||||
})
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,21 @@
|
||||
import { defineConfig } from 'vitest/config'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const p = (rel: string) => fileURLToPath(new URL(rel, import.meta.url))
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
alias: {
|
||||
'@sims/domain': p('./packages/domain/src/index.ts'),
|
||||
'@sims/billing-engine': p('./packages/billing-engine/src/index.ts'),
|
||||
'@sims/config': p('./packages/config/src/index.ts'),
|
||||
'@sims/auth': p('./packages/auth/src/index.ts'),
|
||||
'@sims/scanning': p('./packages/scanning/src/index.ts'),
|
||||
'@sims/search-core': p('./packages/search-core/src/index.ts'),
|
||||
'@sims/printing': p('./packages/printing/src/index.ts'),
|
||||
},
|
||||
},
|
||||
test: {
|
||||
include: ['packages/*/test/**/*.test.ts', 'apps/*/test/**/*.test.ts'],
|
||||
},
|
||||
})
|
||||
Loading…
Reference in New Issue