Skip to content

Commit 3b28b78

Browse files
authored
Merge pull request #14 from rhyek/endpoints-router-register
endpoints-router-register
2 parents c1744f1 + efa80aa commit 3b28b78

File tree

119 files changed

+564
-2580
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+564
-2580
lines changed

.github/workflows/release.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ jobs:
3131

3232
- run: cp README.md ./packages/nestjs-endpoints/README.md
3333

34+
- name: Extract changelog entry
35+
run: ./scripts/change-log-entry.sh ${{ github.ref_name }} > ${{ github.workspace }}/RELEASE_BODY.txt
36+
3437
- name: GitHub Release
3538
uses: softprops/action-gh-release@v2
3639
with:
40+
body_path: ${{ github.workspace }}/RELEASE_BODY.txt
3741
files: |
3842
packages/nestjs-endpoints/package.json
3943
packages/nestjs-endpoints/README.md

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
node_modules/
22
openapi.json
33
*.e2e-spec.ts
4-
!packages/test-endpoints-module/test-app-express-cjs/**/*.e2e-spec.ts
4+
!packages/test/test-app-express-cjs/**/*.e2e-spec.ts
55
generated/
6-
!packages/test-endpoints-module/test-app-express-cjs/generated
6+
!packages/test/test-app-express-cjs/generated

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changelog
2+
3+
## 1.1.0 (2025-03-29)
4+
5+
### Breaking Changes
6+
7+
- Replaced `EndpointsRouterModule.forRoot()` with `EndpointsRouterModule.register()`
8+
- Removed `EndpointsModule` decorator
9+
10+
### Features
11+
12+
- Added support for multiple router registrations in different modules
13+
- Each registration will have its own `rootDirectory` and `baseBath`

README.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { EndpointsRouterModule } from 'nestjs-endpoints';
5050

5151
@Module({
5252
imports: [
53-
EndpointsRouterModule.forRoot({
53+
EndpointsRouterModule.register({
5454
rootDirectory: './endpoints',
5555
providers: [DbService], // available to all endpoints
5656
}),
@@ -125,7 +125,7 @@ null%
125125
# bad input
126126
❯ curl -s -X 'POST' 'http://localhost:3000/user/create' \
127127
-H 'Content-Type: application/json' \
128-
-d '{"name": "Art", "emailTYPO": "art@vandelayindustries.com"}' | jq
128+
-d '{"name": "Art", "emailTYPO": "art@gmail.com"}' | jq
129129
{
130130
"statusCode": 400,
131131
"message": "Validation failed",
@@ -153,7 +153,8 @@ null%
153153

154154
HTTP paths for endpoints are derived from the file's path on disk:
155155

156-
- `rootDirectory` is removed from the start
156+
- `rootDirectory` is trimmed from the start
157+
- Optional `basePath` is prepended
157158
- Path segments that begin with an underscore (`_`) are removed
158159
- Filenames must either end in `.endpoint.ts` or be `endpoint.ts`
159160
- `js`, `cjs`, `mjs`, `mts` are also supported.
@@ -168,20 +169,25 @@ Examples (assume `rootDirectory` is `./endpoints`):
168169
169170
## Advanced Usage
170171

171-
Depending on the project's requirements, the above should ideally suffice most of the time. In case you need access to more of NestJS' features like Interceptors, Guards, access to the request object, etc, or if you'd rather have isolated NestJS modules per feature with their own providers, here is a more complete example:
172+
Depending on the project's requirements, the above should ideally suffice most of the time. In case you need access to more of NestJS' features like Interceptors, Guards, access to the request object, etc, or if you'd rather have contained NestJS modules per feature with their own endpoints
173+
and providers, here is a more complete example (view full example [here](https://github.com/rhyek/nestjs-endpoints/tree/main/packages/test/test-app-express-cjs)):
172174

173175
> _**Note:**_ You are also welcome to use both NestJS Controllers and endpoints in the same project.
174176
175177
`src/app.module.ts`
176178

177179
```typescript
180+
import { Module } from '@nestjs/common';
178181
import { EndpointsRouterModule } from 'nestjs-endpoints';
179182

180183
@Module({
181184
imports: [
182-
EndpointsRouterModule.forRoot({
183-
rootDirectory: './',
184-
autoLoadEndpoints: false, // manually load endpoints
185+
// Contained user module with endpoints
186+
UserModule,
187+
// Other endpoints
188+
EndpointsRouterModule.register({
189+
rootDirectory: './endpoints',
190+
providers: [DbService],
185191
}),
186192
],
187193
})
@@ -191,17 +197,22 @@ export class AppModule {}
191197
`src/user/user.module.ts`
192198

193199
```typescript
194-
import { EndpointsModule } from 'nestjs-endpoints';
195-
import create from './appointment/_endpoints/create/endpoint';
200+
import { Module } from '@nestjs/common';
201+
import { EndpointsRouterModule } from 'nestjs-endpoints';
196202

197-
@EndpointsModule({
198-
endpoints: [create],
199-
providers: [
200-
DbService,
201-
{
202-
provide: AppointmentRepositoryToken,
203-
useClass: AppointmentRepository as IAppointmentRepository,
204-
},
203+
@Module({
204+
imports: [
205+
EndpointsRouterModule.register({
206+
rootDirectory: './',
207+
basePath: 'user',
208+
providers: [
209+
DbService,
210+
{
211+
provide: AppointmentRepositoryToken,
212+
useClass: AppointmentRepository as IAppointmentRepository,
213+
},
214+
],
215+
}),
205216
],
206217
})
207218
export class UserModule {}
@@ -326,4 +337,4 @@ const { id } = await userCreate({
326337
});
327338
```
328339

329-
Have a look at [this](https://github.com/rhyek/nestjs-endpoints/tree/main/packages/test-endpoints-module/test-app-express-cjs) test project to see how you might configure orval to generate an axios-based client and [here](https://github.com/rhyek/nestjs-endpoints/tree/main/packages/test-endpoints-module/test-app-express-cjs/test/client.e2e-spec.ts) to understand how you would use it.
340+
Have a look at [this](https://github.com/rhyek/nestjs-endpoints/tree/main/packages/test/test-app-express-cjs) test project to see how you might configure orval to generate an axios-based client and [here](https://github.com/rhyek/nestjs-endpoints/tree/main/packages/test/test-app-express-cjs/test/client.e2e-spec.ts) to understand how you would use it.
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
export const endpointFileRegex = /\bendpoint\.(js|ts|mjs|cjs|mts)$/;
22

33
export const settings: {
4-
rootDirectory: string | null;
5-
decorateEndpointFns: (() => void)[];
4+
endpoints: {
5+
file: string;
6+
setupFn: (settings: {
7+
rootDirectory: string;
8+
basePath: string;
9+
}) => void;
10+
}[];
611
} = {
7-
rootDirectory: null,
8-
decorateEndpointFns: [],
12+
endpoints: [],
913
};

packages/nestjs-endpoints/src/decorators.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)