Minimal example
Try it
Start your own copy of this example:
npm create @setu-ts my-app -- --example minimal
cd my-app && npm install
npm start
The commands further down run inside a clone of the repository.
The smallest Setu-TS application: the kernel, the runtime plugin, and one route.
pnpm --dir apps/minimal run start
pnpm --dir apps/minimal run smoke
The smoke check proves GET / returns 200 with a JSON greeting without opening a socket.
Read the example deep dive for the concept and source walkthrough.
Read, in order
setu.config.ts
import { createApplication } from '@setu-ts/kernel';
import type { IKernelApplication } from '@setu-ts/kernel';
import { RuntimePlugin } from '@setu-ts/runtime';
/** Builds the smallest useful Setu-TS application, without starting it. */
export function createApp(): IKernelApplication {
const app = createApplication({ plugins: [RuntimePlugin()] });
app.router.get('/', (ctx) => ctx.response.json({ hello: 'world' }));
return app;
}
smoke.ts
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import type { IKernelApplication } from '@setu-ts/kernel';
import { createApp } from './setu.config.ts';
describe('minimal example', () => {
let app: IKernelApplication;
before(async () => {
app = createApp();
await app.start();
});
after(async () => {
await app.stop();
});
it('answers GET / with a greeting', async () => {
const response = await app.inject({ method: 'GET', url: '/' });
assert.equal(response.statusCode, 200);
assert.deepEqual(response.json(), { hello: 'world' });
});
});