Skip to content

Commit

Permalink
Merge pull request #38 from expressots/feature/global-prefix
Browse files Browse the repository at this point in the history
fix: update version && add global route config
  • Loading branch information
rsaz committed Oct 10, 2023
2 parents 0730efe + 2110309 commit 039be2a
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions docs/codebyexample/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,61 @@ export class YourUseUseCase {

There are 4 methods available:

- info: Logs an informational message.
- warn: Logs a warning message.
- error: Logs an error message.
- msg: Logs a message.
- **info**: Logs an informational message.
- **warn**: Logs a warning message.
- **error**: Logs an error message.
- **msg**: Logs a message.

## Setting the Route Global Prefix

You can set a global prefix for all routes in your application. This is useful when you want to version your APIs.

### Non Opinionated Template

You can set the global prefix in the `bootstrap` method of your application.

```typescript
async function bootstrap() {
const app = await AppFactory.create(container, []);

app.setGlobalRoutePrefix("/api");

await app.listen(3000, ServerEnvironment.Development);
}
```

### Opinionated Template

You can set the global prefix in the `configureServices` method of your application.

```typescript
@provide(App)
class App extends AppExpress {
private middleware: IMiddleware;
private provider: IProvider;

constructor() {
super();
this.middleware = container.get<IMiddleware>(Middleware);
this.provider = container.get<IProvider>(Provider);
}

protected configureServices(): void {
this.setGlobalRoutePrefix("/v1");

this.middleware.addBodyParser();
this.middleware.setErrorHandler();
}

protected postServerInitialization(): void {
if (this.isDevelopment()) {
this.provider.envValidator.checkAll();
}
}

protected serverShutdown(): void {}
}
```

---

Expand Down

0 comments on commit 039be2a

Please sign in to comment.