create-acrylblends 0.2.8 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +5 -4
  2. package/dist/index.d.ts +1 -3
  3. package/dist/index.js +20 -198
  4. package/dist/index.js.map +1 -1
  5. package/docs/framework/README.md +2 -2
  6. package/docs/framework/UPSTREAM.md +1 -1
  7. package/docs/framework/getting-started/basic.md +1 -2
  8. package/docs/framework/getting-started/desktop.md +1 -1
  9. package/docs/framework/guides/bring-your-own-tool.md +216 -0
  10. package/docs/framework/guides/create-acrylblends.md +5 -4
  11. package/docs/framework/guides/data.md +2 -1
  12. package/docs/framework/upstream.json +3 -3
  13. package/package.json +2 -3
  14. package/templates/bun/gitignore +0 -2
  15. package/templates/bun/package.json +0 -19
  16. package/templates/bun/src/index.ts +0 -7
  17. package/templates/bun/test/app.test.ts +0 -8
  18. package/templates/bun/tsconfig.json +0 -15
  19. package/templates/chat/gitignore +0 -7
  20. package/templates/chat/migrations/001-chat.sql +0 -12
  21. package/templates/chat/package.json +0 -26
  22. package/templates/chat/src/app.ts +0 -8
  23. package/templates/chat/src/chat-app.ts +0 -100
  24. package/templates/chat/src/client/chat.tsx +0 -115
  25. package/templates/chat/src/client/tsconfig.json +0 -15
  26. package/templates/chat/src/db.ts +0 -53
  27. package/templates/chat/src/index.ts +0 -27
  28. package/templates/chat/src/llm.ts +0 -42
  29. package/templates/chat/src/page.tsx +0 -38
  30. package/templates/chat/test/chat.test.ts +0 -165
  31. package/templates/chat/test/server.test.ts +0 -59
  32. package/templates/chat/tsconfig.json +0 -19
  33. package/templates/nodejs/gitignore +0 -3
  34. package/templates/nodejs/package.json +0 -23
  35. package/templates/nodejs/src/app.ts +0 -10
  36. package/templates/nodejs/src/client/counter.tsx +0 -12
  37. package/templates/nodejs/src/client/tsconfig.json +0 -15
  38. package/templates/nodejs/src/index.ts +0 -21
  39. package/templates/nodejs/src/page.tsx +0 -26
  40. package/templates/nodejs/src/routes.ts +0 -10
  41. package/templates/nodejs/test/app.test.ts +0 -40
  42. package/templates/nodejs/test/server.test.ts +0 -48
  43. package/templates/nodejs/tsconfig.json +0 -19
  44. package/templates/notes/gitignore +0 -7
  45. package/templates/notes/migrations/001-notes.sql +0 -18
  46. package/templates/notes/package.json +0 -26
  47. package/templates/notes/src/app.ts +0 -8
  48. package/templates/notes/src/auth.ts +0 -57
  49. package/templates/notes/src/client/counter.tsx +0 -21
  50. package/templates/notes/src/client/tsconfig.json +0 -15
  51. package/templates/notes/src/db.ts +0 -60
  52. package/templates/notes/src/index.ts +0 -27
  53. package/templates/notes/src/notes-app.ts +0 -205
  54. package/templates/notes/src/schema.ts +0 -38
  55. package/templates/notes/src/views.tsx +0 -134
  56. package/templates/notes/test/notes.test.ts +0 -252
  57. package/templates/notes/test/server.test.ts +0 -59
  58. package/templates/notes/tsconfig.json +0 -19
@@ -1,59 +0,0 @@
1
- import assert from 'node:assert/strict'
2
- import { spawn } from 'node:child_process'
3
- import { once } from 'node:events'
4
- import { mkdtempSync } from 'node:fs'
5
- import { tmpdir } from 'node:os'
6
- import { join } from 'node:path'
7
- import { test } from 'node:test'
8
-
9
- /** Start `src/index.ts` the way `npm start` does, on a port the system chooses, and read the address it prints. */
10
- async function start(env: Record<string, string> = {}) {
11
- const child = spawn(
12
- process.execPath,
13
- ['--import', '__PACKAGE__/node-server/register', 'src/index.ts'],
14
- {
15
- env: {
16
- ...process.env,
17
- PORT: '0',
18
- CHAT_DB: join(mkdtempSync(join(tmpdir(), 'chat-')), 'chat.sqlite'),
19
- ...env,
20
- },
21
- stdio: ['ignore', 'pipe', 'inherit'],
22
- },
23
- )
24
- let out = ''
25
- const address = await new Promise<string>((resolve, reject) => {
26
- child.once('exit', (code) =>
27
- reject(new Error(`the server exited with ${code} before it listened`)),
28
- )
29
- child.stdout.on('data', (chunk) => {
30
- out += chunk
31
- const match = /listening on (http:\/\/\S+)/.exec(out)
32
- if (match?.[1]) resolve(match[1])
33
- })
34
- })
35
- return { child, address }
36
- }
37
-
38
- test('the server listens on 127.0.0.1 unless HOST says otherwise', async () => {
39
- const { child, address } = await start()
40
- try {
41
- assert.match(address, /^http:\/\/127\.0\.0\.1:\d+$/)
42
- } finally {
43
- child.kill('SIGTERM')
44
- await once(child, 'exit')
45
- }
46
- })
47
-
48
- for (const signal of ['SIGTERM', 'SIGINT'] as const) {
49
- test(`${signal} stops the server cleanly and frees the port`, async () => {
50
- const { child, address } = await start()
51
- assert.equal((await fetch(`${address}/`)).status, 200)
52
- const started = Date.now()
53
- child.kill(signal)
54
- const [code] = await once(child, 'exit')
55
- assert.equal(code, 0)
56
- assert.ok(Date.now() - started < 5000, 'the server took too long to stop')
57
- await assert.rejects(fetch(address), 'the port should be free')
58
- })
59
- }
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2024",
4
- "lib": ["ES2024", "DOM", "DOM.Iterable"],
5
- "module": "NodeNext",
6
- "moduleResolution": "NodeNext",
7
- "strict": true,
8
- "verbatimModuleSyntax": true,
9
- "erasableSyntaxOnly": true,
10
- "allowImportingTsExtensions": true,
11
- "noEmit": true,
12
- "skipLibCheck": true,
13
- "types": ["node"],
14
- "jsx": "react-jsx",
15
- "jsxImportSource": "__PACKAGE__/jsx"
16
- },
17
- "include": ["src", "test"],
18
- "exclude": ["src/client"]
19
- }
@@ -1,3 +0,0 @@
1
- node_modules/
2
- dist/
3
- .acryl/
@@ -1,23 +0,0 @@
1
- {
2
- "name": "__APP_NAME__",
3
- "version": "0.1.0",
4
- "private": true,
5
- "type": "module",
6
- "engines": {
7
- "node": ">=22.19.0"
8
- },
9
- "scripts": {
10
- "dev": "node --watch --import acrylblends/node-server/register src/index.ts",
11
- "start": "node --import acrylblends/node-server/register src/index.ts",
12
- "test": "acrylblends check-deps && node --import acrylblends/node-server/register --test \"test/**/*.test.{ts,tsx}\"",
13
- "check": "tsc --noEmit && tsc --noEmit -p src/client && acrylblends check-deps",
14
- "build": "acrylblends build-client"
15
- },
16
- "dependencies": {
17
- "__PACKAGE__": "__RANGE__",
18
- "typescript": "6.0.3"
19
- },
20
- "devDependencies": {
21
- "@types/node": "^24.0.0"
22
- }
23
- }
@@ -1,10 +0,0 @@
1
- import { __CLASS__ } from '__PACKAGE__'
2
- import { clientModules } from '__PACKAGE__/node-server'
3
- import { routes } from './routes.ts'
4
-
5
- // Client components without a bundler: src/client is compiled when the browser asks; `npm run build` compiles it once for production (NODE_ENV=production serves only dist/client).
6
- const app = new __CLASS__()
7
- .route('/', routes)
8
- .route('/client', clientModules({ root: 'src/client', compiled: 'dist/client' }))
9
-
10
- export default app
@@ -1,12 +0,0 @@
1
- import { render, useState } from '__PACKAGE__/jsx/dom'
2
-
3
- const Counter = () => {
4
- const [count, setCount] = useState(0)
5
- return (
6
- <button type="button" onClick={() => setCount(count + 1)}>
7
- Count {count}
8
- </button>
9
- )
10
- }
11
-
12
- render(<Counter />, document.getElementById('counter')!)
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2024",
4
- "lib": ["ES2024", "DOM", "DOM.Iterable"],
5
- "module": "NodeNext",
6
- "moduleResolution": "NodeNext",
7
- "strict": true,
8
- "noEmit": true,
9
- "allowImportingTsExtensions": true,
10
- "jsx": "react-jsx",
11
- "jsxImportSource": "__PACKAGE__/jsx/dom",
12
- "types": []
13
- },
14
- "include": ["**/*.ts", "**/*.tsx"]
15
- }
@@ -1,21 +0,0 @@
1
- import { serve } from '__PACKAGE__/node-server'
2
- import app from './app.ts'
3
-
4
- const port = Number(process.env.PORT || 3000)
5
- // Local by default. Behind a reverse proxy on the same machine this is right; in a container set HOST=0.0.0.0.
6
- const hostname = process.env.HOST || '127.0.0.1'
7
-
8
- const server = serve({ fetch: app.fetch, port, hostname }, (info) => {
9
- console.log(`listening on http://${info.address}:${info.port}`)
10
- })
11
-
12
- // Stop taking requests, let the ones in flight finish, then exit. A connection that never ends cannot keep the process alive past 10 seconds.
13
- function shutdown(): void {
14
- server.close(() => {
15
- process.exit(0)
16
- })
17
- server.closeIdleConnections()
18
- setTimeout(() => process.exit(1), 10_000).unref()
19
- }
20
- process.once('SIGINT', shutdown)
21
- process.once('SIGTERM', shutdown)
@@ -1,26 +0,0 @@
1
- /** A page written in JSX: Node.js runs it through `acrylblends/node-server/register` (see the scripts in package.json), which compiles .tsx with this app's own typescript. */
2
- const About = () => (
3
- <main>
4
- <h1>About</h1>
5
- <p>Rendered on the server with __PACKAGE__/jsx.</p>
6
- </main>
7
- )
8
-
9
- export const aboutPage = (): string => (<About />).toString()
10
-
11
- /** Throws on purpose: the template's test checks that the stack names this file, so a failure in your own pages points at the .tsx line. */
12
- export const failingPage = (): string => {
13
- throw new Error('a page failed')
14
- }
15
-
16
- /** A page with one client component: `src/client/counter.tsx` runs in the browser, compiled on request by `clientModules` (see src/app.ts). */
17
- export const counterPage = (): string =>
18
- (
19
- <html lang="en">
20
- <body>
21
- <h1>Counter</h1>
22
- <div id="counter" />
23
- <script type="module" src="/client/counter.tsx" />
24
- </body>
25
- </html>
26
- ).toString()
@@ -1,10 +0,0 @@
1
- import { __CLASS__ } from '__PACKAGE__'
2
- import { aboutPage, counterPage } from './page.tsx'
3
-
4
- /** The routes, in a file that does not import the Node adapter, so browser code can import the type: `import type { AppType } from '../routes.ts'`. */
5
- export const routes = new __CLASS__()
6
- .get('/', (c) => c.text('__CLASS__!'))
7
- .get('/about', (c) => c.html(aboutPage()))
8
- .get('/counter', (c) => c.html(counterPage()))
9
-
10
- export type AppType = typeof routes
@@ -1,40 +0,0 @@
1
- import assert from 'node:assert/strict'
2
- import { test } from 'node:test'
3
- import app from '../src/app.ts'
4
-
5
- test('GET / answers __CLASS__!', async () => {
6
- const response = await app.request('/')
7
- assert.equal(response.status, 200)
8
- assert.equal(await response.text(), '__CLASS__!')
9
- })
10
-
11
- test('GET /about renders the JSX page', async () => {
12
- const response = await app.request('/about')
13
- assert.equal(response.status, 200)
14
- assert.match(response.headers.get('content-type') ?? '', /html/)
15
- assert.match(
16
- await response.text(),
17
- /<main><h1>About<\/h1><p>Rendered on the server with __PACKAGE__\/jsx\.<\/p><\/main>/,
18
- )
19
- })
20
-
21
- test('an error thrown in a .tsx file names the .tsx line in its stack', async () => {
22
- const { failingPage } = await import('../src/page.tsx')
23
- let stack = ''
24
- try {
25
- failingPage()
26
- } catch (error) {
27
- stack = String((error as Error).stack)
28
- }
29
- assert.match(stack, /page\.tsx:\d+/)
30
- })
31
-
32
- test('GET /counter serves a page with a client component, and the component is compiled for the browser', async () => {
33
- const page = await app.request('/counter')
34
- assert.equal(page.status, 200)
35
- assert.match(await page.text(), /<script type="module" src="\/client\/counter\.tsx">/)
36
- const module = await app.request('/client/counter.tsx')
37
- assert.equal(module.status, 200)
38
- assert.match(module.headers.get('content-type') ?? '', /javascript/)
39
- assert.doesNotMatch(await module.text(), /<Counter|<button/)
40
- })
@@ -1,48 +0,0 @@
1
- import assert from 'node:assert/strict'
2
- import { spawn } from 'node:child_process'
3
- import { once } from 'node:events'
4
- import { test } from 'node:test'
5
-
6
- /** Start `src/index.ts` the way `npm start` does, on a port the system chooses, and read the address it prints. */
7
- async function start(env: Record<string, string> = {}) {
8
- const child = spawn(
9
- process.execPath,
10
- ['--import', '__PACKAGE__/node-server/register', 'src/index.ts'],
11
- { env: { ...process.env, PORT: '0', ...env }, stdio: ['ignore', 'pipe', 'inherit'] },
12
- )
13
- let out = ''
14
- const address = await new Promise<string>((resolve, reject) => {
15
- child.once('exit', (code) =>
16
- reject(new Error(`the server exited with ${code} before it listened`)),
17
- )
18
- child.stdout.on('data', (chunk) => {
19
- out += chunk
20
- const match = /listening on (http:\/\/\S+)/.exec(out)
21
- if (match?.[1]) resolve(match[1])
22
- })
23
- })
24
- return { child, address }
25
- }
26
-
27
- test('the server listens on 127.0.0.1 unless HOST says otherwise', async () => {
28
- const { child, address } = await start()
29
- try {
30
- assert.match(address, /^http:\/\/127\.0\.0\.1:\d+$/)
31
- } finally {
32
- child.kill('SIGTERM')
33
- await once(child, 'exit')
34
- }
35
- })
36
-
37
- for (const signal of ['SIGTERM', 'SIGINT'] as const) {
38
- test(`${signal} stops the server cleanly and frees the port`, async () => {
39
- const { child, address } = await start()
40
- assert.equal((await fetch(address)).status, 200)
41
- const started = Date.now()
42
- child.kill(signal)
43
- const [code] = await once(child, 'exit')
44
- assert.equal(code, 0)
45
- assert.ok(Date.now() - started < 5000, 'the server took too long to stop')
46
- await assert.rejects(fetch(address), 'the port should be free')
47
- })
48
- }
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2024",
4
- "lib": ["ES2024", "DOM", "DOM.Iterable"],
5
- "module": "NodeNext",
6
- "moduleResolution": "NodeNext",
7
- "strict": true,
8
- "verbatimModuleSyntax": true,
9
- "erasableSyntaxOnly": true,
10
- "allowImportingTsExtensions": true,
11
- "noEmit": true,
12
- "skipLibCheck": true,
13
- "types": ["node"],
14
- "jsx": "react-jsx",
15
- "jsxImportSource": "__PACKAGE__/jsx"
16
- },
17
- "include": ["src", "test"],
18
- "exclude": ["src/client"]
19
- }
@@ -1,7 +0,0 @@
1
- node_modules/
2
- data/
3
- *.sqlite
4
- *.sqlite-*
5
- .acrylblends/
6
- dist/
7
- .acryl/
@@ -1,18 +0,0 @@
1
- CREATE TABLE users (
2
- id INTEGER PRIMARY KEY,
3
- email TEXT NOT NULL UNIQUE,
4
- password_hash TEXT NOT NULL
5
- );
6
-
7
- CREATE TABLE sessions (
8
- token TEXT PRIMARY KEY,
9
- user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE
10
- );
11
-
12
- CREATE TABLE notes (
13
- id INTEGER PRIMARY KEY,
14
- user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
15
- title TEXT NOT NULL,
16
- body TEXT NOT NULL,
17
- updated_at TEXT NOT NULL
18
- );
@@ -1,26 +0,0 @@
1
- {
2
- "name": "__APP_NAME__",
3
- "version": "0.1.0",
4
- "private": true,
5
- "type": "module",
6
- "acryl": {
7
- "opener": "src/db.ts"
8
- },
9
- "engines": {
10
- "node": ">=22.19.0"
11
- },
12
- "scripts": {
13
- "dev": "node --watch --import acrylblends/node-server/register src/index.ts",
14
- "start": "node --import acrylblends/node-server/register src/index.ts",
15
- "test": "acrylblends check-deps && node --import acrylblends/node-server/register --test \"test/**/*.test.{ts,tsx}\"",
16
- "check": "tsc --noEmit && tsc --noEmit -p src/client && acrylblends check-deps",
17
- "build": "acrylblends build-client"
18
- },
19
- "dependencies": {
20
- "__PACKAGE__": "__RANGE__",
21
- "typescript": "6.0.3"
22
- },
23
- "devDependencies": {
24
- "@types/node": "^24.0.0"
25
- }
26
- }
@@ -1,8 +0,0 @@
1
- import { openNotesDb } from './db.ts'
2
- import { createApp } from './notes-app.ts'
3
-
4
- /** The composition root: opens the database (once) and builds the app. `index.ts` serves it; the desktop shell does too, and calls `close` when it stops. */
5
- const { db, close } = await openNotesDb()
6
-
7
- export { close }
8
- export default createApp(db)
@@ -1,57 +0,0 @@
1
- import type { Db } from '__PACKAGE__/db'
2
- import { randomBytes, scrypt, timingSafeEqual } from 'node:crypto'
3
- import { promisify } from 'node:util'
4
-
5
- const scryptAsync = promisify(scrypt) as (
6
- password: string,
7
- salt: Buffer,
8
- length: number,
9
- ) => Promise<Buffer>
10
-
11
- export async function hashPassword(password: string): Promise<string> {
12
- const salt = randomBytes(16)
13
- const key = await scryptAsync(password, salt, 64)
14
- return `${salt.toString('hex')}:${key.toString('hex')}`
15
- }
16
-
17
- export async function verifyPassword(password: string, stored: string): Promise<boolean> {
18
- const [salt, key] = stored.split(':')
19
- if (!salt || !key) return false
20
- const expected = Buffer.from(key, 'hex')
21
- const actual = await scryptAsync(password, Buffer.from(salt, 'hex'), expected.length)
22
- return timingSafeEqual(actual, expected)
23
- }
24
-
25
- export function authStore(db: Db) {
26
- return {
27
- findUser(email: string) {
28
- return db.get<{ id: number; email: string; password_hash: string }>(
29
- 'SELECT id, email, password_hash FROM users WHERE email = ?',
30
- email,
31
- )
32
- },
33
- async createUser(email: string, password: string): Promise<number> {
34
- const user = await db.get<{ id: number }>(
35
- 'INSERT INTO users (email, password_hash) VALUES (?, ?) RETURNING id',
36
- email,
37
- await hashPassword(password),
38
- )
39
- return user!.id
40
- },
41
- async startSession(userId: number): Promise<string> {
42
- const token = randomBytes(32).toString('hex')
43
- await db.run('INSERT INTO sessions (token, user_id) VALUES (?, ?)', token, userId)
44
- return token
45
- },
46
- async userFor(token: string | undefined) {
47
- if (!token) return undefined
48
- return db.get<{ id: number; email: string }>(
49
- 'SELECT users.id AS id, users.email AS email FROM sessions JOIN users ON users.id = sessions.user_id WHERE token = ?',
50
- token,
51
- )
52
- },
53
- async endSession(token: string): Promise<void> {
54
- await db.run('DELETE FROM sessions WHERE token = ?', token)
55
- },
56
- }
57
- }
@@ -1,21 +0,0 @@
1
- import { render, useEffect, useState } from '__PACKAGE__/jsx/dom'
2
-
3
- /** The live character counter of the note form: a client component drawn next to the textarea, compiled on request by clientModules (see src/notes-app.ts). */
4
- const Count = ({ area }: { area: HTMLTextAreaElement }) => {
5
- const [length, setLength] = useState(area.value.length)
6
- useEffect(() => {
7
- const update = () => setLength(area.value.length)
8
- area.addEventListener('input', update)
9
- return () => area.removeEventListener('input', update)
10
- }, [])
11
- return (
12
- <>
13
- {length} / {area.maxLength}
14
- </>
15
- )
16
- }
17
-
18
- const area = document.getElementById('body')
19
- const out = document.querySelector('[data-island="counter"]')
20
- if (area instanceof HTMLTextAreaElement && out instanceof HTMLElement)
21
- render(<Count area={area} />, out)
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2024",
4
- "lib": ["ES2024", "DOM", "DOM.Iterable"],
5
- "module": "NodeNext",
6
- "moduleResolution": "NodeNext",
7
- "strict": true,
8
- "noEmit": true,
9
- "allowImportingTsExtensions": true,
10
- "jsx": "react-jsx",
11
- "jsxImportSource": "__PACKAGE__/jsx/dom",
12
- "types": []
13
- },
14
- "include": ["**/*.ts", "**/*.tsx"]
15
- }
@@ -1,60 +0,0 @@
1
- import type { Db } from '__PACKAGE__/db'
2
- import { openDb } from '__PACKAGE__/db/sqlite'
3
- import { fileURLToPath } from 'node:url'
4
-
5
- export interface Note {
6
- id: number
7
- user_id: number
8
- title: string
9
- body: string
10
- updated_at: string
11
- }
12
-
13
- /** The folder of numbered SQL files (001-notes.sql, ...). Applied on start, each once, in one transaction. */
14
- const MIGRATIONS = fileURLToPath(new URL('../migrations', import.meta.url))
15
-
16
- /** Open the notes database and apply the migrations. Call `close` once, when the process stops. */
17
- export function openNotesDb(path = process.env.NOTES_DB ?? 'data/notes.sqlite') {
18
- return openDb({ path, migrations: MIGRATIONS })
19
- }
20
-
21
- export function notesStore(db: Db) {
22
- return {
23
- list(userId: number, q = ''): Promise<Note[]> {
24
- const like = `%${q.replace(/[\\%_]/g, (m) => `\\${m}`)}%`
25
- return db.all<Note>(
26
- `SELECT * FROM notes WHERE user_id = ? AND (title LIKE ? ESCAPE '\\' OR body LIKE ? ESCAPE '\\') ORDER BY updated_at DESC, id DESC`,
27
- userId,
28
- like,
29
- like,
30
- )
31
- },
32
- get(userId: number, id: number): Promise<Note | undefined> {
33
- return db.get<Note>('SELECT * FROM notes WHERE id = ? AND user_id = ?', id, userId)
34
- },
35
- async create(userId: number, title: string, body: string): Promise<Note> {
36
- const note = await db.get<Note>(
37
- 'INSERT INTO notes (user_id, title, body, updated_at) VALUES (?, ?, ?, ?) RETURNING *',
38
- userId,
39
- title,
40
- body,
41
- new Date().toISOString(),
42
- )
43
- return note!
44
- },
45
- update(userId: number, id: number, title: string, body: string): Promise<Note | undefined> {
46
- return db.get<Note>(
47
- 'UPDATE notes SET title = ?, body = ?, updated_at = ? WHERE id = ? AND user_id = ? RETURNING *',
48
- title,
49
- body,
50
- new Date().toISOString(),
51
- id,
52
- userId,
53
- )
54
- },
55
- async remove(userId: number, id: number): Promise<boolean> {
56
- const { changes } = await db.run('DELETE FROM notes WHERE id = ? AND user_id = ?', id, userId)
57
- return changes > 0
58
- },
59
- }
60
- }
@@ -1,27 +0,0 @@
1
- import { serve } from '__PACKAGE__/node-server'
2
- import app, { close } from './app.ts'
3
-
4
- const port = Number(process.env.PORT || 3000)
5
- // Local by default. Behind a reverse proxy on the same machine this is right; in a container set HOST=0.0.0.0.
6
- const hostname = process.env.HOST || '127.0.0.1'
7
-
8
- const server = serve({ fetch: app.fetch, port, hostname }, (info) => {
9
- console.log(`listening on http://${info.address}:${info.port}`)
10
- })
11
-
12
- // Stop taking requests, let the ones in flight finish, then close the database and exit. A connection that never ends cannot keep the process alive past 10 seconds.
13
- function shutdown(): void {
14
- server.close(() => {
15
- close().then(
16
- () => process.exit(0),
17
- (error) => {
18
- console.error(error)
19
- process.exit(1)
20
- },
21
- )
22
- })
23
- server.closeIdleConnections()
24
- setTimeout(() => process.exit(1), 10_000).unref()
25
- }
26
- process.once('SIGINT', shutdown)
27
- process.once('SIGTERM', shutdown)