Skip to content

Commit 5ed1fe1

Browse files
committed
feat: add runtime interaction guides for Express and H3, update README files
1 parent f025870 commit 5ed1fe1

File tree

8 files changed

+220
-14
lines changed

8 files changed

+220
-14
lines changed

docs/.vitepress/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export default defineConfig({
3838
{ text: 'Getting Started', link: '/guide/getting-started' },
3939
{ text: 'CLI', link: '/guide/cli' },
4040
{ text: 'Database & Modeling', link: '/guide/database-modeling' },
41+
{ text: 'Express Runtime Interaction', link: '/guide/express-runtime' },
42+
{ text: 'H3 Runtime Interaction', link: '/guide/h3-runtime' },
4143
{ text: 'API Reference', link: '/api' },
4244
]
4345
},

docs/guide/express-runtime.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Express Runtime Interaction
2+
3+
This page documents every supported way to interact directly with Arkstack's Express runtime.
4+
5+
## Bootstrap Exports
6+
7+
From `src/core/bootstrap.ts`:
8+
9+
- `expressApp`: raw Express instance
10+
- `app`: Arkstack `Application` instance
11+
12+
```ts
13+
import { app, expressApp } from 'src/core/bootstrap';
14+
```
15+
16+
## Interaction Options
17+
18+
### 1. Raw runtime: `expressApp`
19+
20+
Use this for direct Express APIs.
21+
22+
```ts
23+
import { expressApp } from 'src/core/bootstrap';
24+
25+
expressApp.set('trust proxy', 1);
26+
expressApp.disable('x-powered-by');
27+
expressApp.locals.serviceName = 'api';
28+
```
29+
30+
### 2. Instance runtime accessor: `app.getAppInstance()`
31+
32+
Get the runtime instance from the Arkstack wrapper.
33+
34+
```ts
35+
import { app } from 'src/core/bootstrap';
36+
37+
const runtime = app.getAppInstance();
38+
runtime.use((req, _res, next) => {
39+
req.headers['x-runtime'] = 'express';
40+
next();
41+
});
42+
```
43+
44+
### 3. Static runtime accessor: `Application.getAppInstance()`
45+
46+
Access the static runtime reference.
47+
48+
```ts
49+
import Application from 'src/core/app';
50+
51+
const runtime = Application.getAppInstance();
52+
runtime.set('etag', false);
53+
```
54+
55+
### 4. Driver interaction: `app.getDriver()`
56+
57+
Use the runtime driver for lifecycle-level integration.
58+
59+
```ts
60+
import { app } from 'src/core/bootstrap';
61+
62+
const driver = app.getDriver();
63+
const runtime = app.getAppInstance();
64+
await driver.applyMiddleware(runtime, (req, _res, next) => next());
65+
```
66+
67+
### 5. Router contract interaction: `app.getRouter()`
68+
69+
Use the framework-agnostic router contract.
70+
71+
```ts
72+
import { app } from 'src/core/bootstrap';
73+
74+
const router = app.getRouter();
75+
await router.bind(app.getAppInstance());
76+
77+
const routes = await router.list({ path: '/api' });
78+
console.log(routes);
79+
```
80+
81+
### 6. Lifecycle control: `boot` and `shutdown`
82+
83+
```ts
84+
import { app } from 'src/core/bootstrap';
85+
86+
await app.boot(3000);
87+
// later
88+
await app.shutdown();
89+
```
90+
91+
## Notes
92+
93+
- `app.boot(port)` mounts public assets, binds router, applies middleware, registers error handling, starts the server, and attaches graceful shutdown.
94+
- Use the router contract (`getRouter`) for framework-agnostic behavior where possible.
95+
- Prefer `expressApp` only when you specifically need native Express APIs.

docs/guide/h3-runtime.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# H3 Runtime Interaction
2+
3+
This page documents every supported way to interact directly with Arkstack's H3 runtime.
4+
5+
## Bootstrap Exports
6+
7+
From `src/core/bootstrap.ts`:
8+
9+
- `h3App`: raw H3 instance
10+
- `app`: Arkstack `Application` instance
11+
12+
```ts
13+
import { app, h3App } from 'src/core/bootstrap';
14+
```
15+
16+
## Interaction Options
17+
18+
### 1. Raw runtime: `h3App`
19+
20+
Use this for direct H3 APIs.
21+
22+
```ts
23+
import { h3App } from 'src/core/bootstrap';
24+
import { HTTPResponse } from 'h3';
25+
26+
h3App.get('/health', () => {
27+
return new HTTPResponse('ok');
28+
});
29+
```
30+
31+
### 2. Instance runtime accessor: `app.getAppInstance()`
32+
33+
Get the runtime instance from the Arkstack wrapper.
34+
35+
```ts
36+
import { app } from 'src/core/bootstrap';
37+
38+
const runtime = app.getAppInstance();
39+
runtime.use((event) => {
40+
event.context.source = 'arkstack';
41+
});
42+
```
43+
44+
### 3. Static runtime accessor: `Application.getAppInstance()`
45+
46+
Access the static runtime reference.
47+
48+
```ts
49+
import Application from 'src/core/app';
50+
51+
const runtime = Application.getAppInstance();
52+
runtime.use(() => {
53+
// global middleware hook
54+
});
55+
```
56+
57+
### 4. Driver interaction: `app.getDriver()`
58+
59+
Use the runtime driver for lifecycle-level integration.
60+
61+
```ts
62+
import { app } from 'src/core/bootstrap';
63+
64+
const driver = app.getDriver();
65+
const runtime = app.getAppInstance();
66+
await driver.applyMiddleware(runtime, () => {});
67+
```
68+
69+
### 5. Router contract interaction: `app.getRouter()`
70+
71+
Use the framework-agnostic router contract.
72+
73+
```ts
74+
import { app } from 'src/core/bootstrap';
75+
76+
const router = app.getRouter();
77+
await router.bind(app.getAppInstance());
78+
79+
const routes = await router.list({ path: '/api' }, app.getAppInstance());
80+
console.log(routes);
81+
```
82+
83+
### 6. Lifecycle control: `boot` and `shutdown`
84+
85+
```ts
86+
import { app } from 'src/core/bootstrap';
87+
88+
await app.boot(3000);
89+
// later
90+
await app.shutdown();
91+
```
92+
93+
## Notes
94+
95+
- `app.boot(port)` mounts public assets, binds router, applies middleware, starts the server, and attaches graceful shutdown.
96+
- Use the router contract (`getRouter`) for framework-agnostic behavior where possible.
97+
- Prefer `h3App` only when you specifically need native H3 APIs.

express/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Arkstack Express.js
22

3-
Express.js app scaffolded with Tonelix's Arkstack
3+
Express.js app scaffolded with Toneflix's Arkstack.
4+
5+
Full framework documentations are available from [https://arkstack.toneflix.net](https://arkstack.toneflix.net/).
6+
7+
- Runtime interaction guide: [guide/express-runtime](https://arkstack.toneflix.net/guide/express-runtime)
8+
- Getting started guide: [guide/getting-started](https://arkstack.toneflix.net/guide/getting-started)
49

510
## Developing
611

@@ -16,13 +21,13 @@ npm install
1621
npx prisma generate
1722
```
1823

19-
### Run Migrations
24+
### Run migrations
2025

2126
```sh
2227
npx prisma migrate dev
2328
```
2429

25-
### Start Dev Server
30+
### Start dev server
2631

2732
```sh
2833
npm run dev

express/src/core/bootstrap.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Application from 'src/core/app'
22
import express from 'express'
33

4-
export const app = new Application(express())
4+
export const expressApp = express()
5+
6+
export const app = new Application(expressApp)

express/src/core/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class Router extends ClearRouter {
3333

3434
static async list (_options: ArkstackRouteListOptions = {}) {
3535
await this.bind()
36-
37-
return this.allRoutes()
36+
37+
return this.allRoutes()
3838
}
3939
}

h3/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Arkstack H3.js
22

3-
H3.js app scaffolded with Tonelix's Arkstack
3+
H3.js app scaffolded with Toneflix's Arkstack.
4+
5+
Full framework documentations are available from [https://arkstack.toneflix.net](https://arkstack.toneflix.net/).
6+
7+
- Runtime interaction guide: [guide/h3-runtime](https://arkstack.toneflix.net/guide/h3-runtime)
8+
- Getting started guide: [guide/getting-started](https://arkstack.toneflix.net/guide/getting-started)
49

510
## Developing
611

@@ -16,13 +21,13 @@ npm install
1621
npx prisma generate
1722
```
1823

19-
### Run Migrations
24+
### Run migrations
2025

2126
```sh
2227
npx prisma migrate dev
2328
```
2429

25-
### Start Dev Server
30+
### Start dev server
2631

2732
```sh
2833
npm run dev

h3/src/core/bootstrap.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import Application from 'src/core/app'
22
import ErrorHandler from './utils/request-handlers'
33
import { H3 } from 'h3'
44

5-
export const app = new Application(
6-
new H3({
7-
onError: ErrorHandler,
8-
}),
9-
)
5+
export const h3App = new H3({
6+
onError: ErrorHandler,
7+
})
8+
9+
export const app = new Application(h3App)

0 commit comments

Comments
 (0)