@decohere/create 0.0.1-dev.20261110.311 → 0.0.1-dev.20261110.318
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.
- package/README.md +21 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -82,11 +82,15 @@ my-app/
|
|
|
82
82
|
Dockerfile # copies .package/ (written by `forge package`)
|
|
83
83
|
.dockerignore
|
|
84
84
|
src/
|
|
85
|
-
|
|
85
|
+
app.ts # createApp(): the app's composition and your services
|
|
86
|
+
main.ts # starts it
|
|
86
87
|
sample.config.ts
|
|
87
|
-
|
|
88
|
+
services/
|
|
89
|
+
sample.service.ts
|
|
88
90
|
controllers/
|
|
89
91
|
hello.controller.ts
|
|
92
|
+
tests/
|
|
93
|
+
hello.controller.spec.ts # GET /hello over HTTP, no database or Docker
|
|
90
94
|
```
|
|
91
95
|
|
|
92
96
|
Every API gets its own `projects/<name>/Dockerfile`; that folder is the Docker build context. The Dockerfile copies `.package/`, which `forge package` writes (see below).
|
|
@@ -101,6 +105,20 @@ RUN apt-get update && apt-get install -y --no-install-recommends g++ make python
|
|
|
101
105
|
USER node
|
|
102
106
|
```
|
|
103
107
|
|
|
108
|
+
#### The app and its test
|
|
109
|
+
|
|
110
|
+
`src/app.ts` is the app's composition, written out so you can see and change every part: Pino logging, `http(FastifyProvider, …)` with an OpenAPI document, `config(…)` from `config/` and the environment, and `health()`. To use another HTTP provider or logger, edit that line; nothing is hidden behind a preset ([architecture: progressive](../../docs/architecture/README.md#4-progressive-new-apps-start-from-a-recipe-the-app-owns)). `src/main.ts` only starts it:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { createApp } from "./app.js";
|
|
114
|
+
|
|
115
|
+
const app = await createApp();
|
|
116
|
+
await app.start({ port: Number(process.env.PORT ?? 3000) });
|
|
117
|
+
export default app;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`tests/hello.controller.spec.ts` boots the Hello controller as a real app on a free port and calls `GET /hello`, with no database, Auth0 or Docker, so `pnpm test` passes in a new project. Copy it for your own controllers; [Testing an app](../http/README.md#testing-an-app) shows how to test the whole app instead.
|
|
121
|
+
|
|
104
122
|
#### Scripts
|
|
105
123
|
|
|
106
124
|
| Script | Command | When |
|
|
@@ -151,7 +169,7 @@ In the project's Dev Container:
|
|
|
151
169
|
pnpm decohere add auth0
|
|
152
170
|
```
|
|
153
171
|
|
|
154
|
-
This logs in if needed, creates the Auth0 API and a `<project> Dev` login app, writes `AUTH0_ISSUER_BASE_URL`, `AUTH0_AUDIENCE` and `AUTH0_CLIENT_ID` to `.env`, adds the `auth` section to `config/config.yaml`, and adds `.use(auth())` to each API's `
|
|
172
|
+
This logs in if needed, creates the Auth0 API and a `<project> Dev` login app, writes `AUTH0_ISSUER_BASE_URL`, `AUTH0_AUDIENCE` and `AUTH0_CLIENT_ID` to `.env`, adds the `auth` section to `config/config.yaml`, and adds `.use(auth())` to each API's `app.ts`. Running it again changes nothing. If an `app.ts` no longer has the generated shape, the command leaves it alone and prints the lines to add. It also creates a `<project> Token` machine app (written to `.env` as `AUTH0_TOKEN_CLIENT_ID`). It doesn't add the local user profile a new project with Postgres gets.
|
|
155
173
|
|
|
156
174
|
Once Auth0 is added, **every route needs a token** unless it has `@AllowAnonymous()`, because `auth()` is secure by default. To call one, in the Dev Container:
|
|
157
175
|
|