Skip to content

Commit

Permalink
Deprecate displayServerURL
Browse files Browse the repository at this point in the history
  • Loading branch information
LoicPoullain committed Aug 3, 2024
1 parent 9489962 commit 3d5c845
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
3 changes: 2 additions & 1 deletion docs/docs/common/websockets.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ import * as http from 'http';

async function main() {
const serviceManager = new ServiceManager();
const logger = serviceManager.get(Logger);

const app = await createApp(AppController, { serviceManager });

const httpServer = http.createServer(app);
// Instanciate, init and connect websocket controllers.
await serviceManager.get(WebsocketController).attachHttpServer(httpServer);
httpServer.listen(port, () => displayServerURL(port));
httpServer.listen(port, () => logger.info(`Listening on port ${port}...`));
}

```
Expand Down
7 changes: 5 additions & 2 deletions docs/docs/security/rate-limiting.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ npm install express express-rate-limit
*src/index.ts*
```typescript
// 3p
import { Config, createApp, displayServerURL } from '@foal/core';
import { Config, createApp, Logger, ServiceManager } from '@foal/core';
import * as express from 'express';
import * as rateLimit from 'express-rate-limit';

Expand All @@ -41,11 +41,14 @@ async function main() {
res.status(this.statusCode || 429).send(this.message);
}
}));

const serviceManager = new ServiceManager();
const logger = serviceManager.get(Logger);

const app = await createApp(AppController, { expressInstance: expressApp });

const port = Config.get('port', 'number', 3001);
app.listen(port, () => displayServerURL(port));
app.listen(port, () => logger.info(`Listening on port ${port}...`));
}

main()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 3p
import { Config, createApp, displayServerURL } from '@foal/core';
import { Config, createApp, Logger, ServiceManager } from '@foal/core';
import * as express from 'express';
import * as rateLimit from 'express-rate-limit';

Expand Down Expand Up @@ -28,9 +28,12 @@ it('[Docs] Cookbook > Limit Repeated Requests', () => {
}
}));

const serviceManager = new ServiceManager();
const logger = serviceManager.get(Logger);

const app = await createApp(AppController, { expressInstance: expressApp });

const port = Config.get('port', 'number', 3001);
app.listen(port, () => displayServerURL(port));
app.listen(port, () => logger.info(`Listening on port ${port}...`));
}
});
9 changes: 6 additions & 3 deletions packages/cli/src/generate/specs/app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'source-map-support/register';

// 3p
import { Config, createApp, displayServerURL } from '@foal/core';
import { Config, createApp, Logger, ServiceManager } from '@foal/core';

// App
import { AppController } from './app/app.controller';
Expand All @@ -10,10 +10,13 @@ import { dataSource } from './db';
async function main() {
await dataSource.initialize();

const app = await createApp(AppController);
const serviceManager = new ServiceManager();
const logger = serviceManager.get(Logger);

const app = await createApp(AppController, { serviceManager });

const port = Config.get('port', 'number', 3001);
app.listen(port, () => displayServerURL(port));
app.listen(port, () => logger.info(`Listening on port ${port}...`));
}

main()
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/src/generate/templates/app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'source-map-support/register';

// 3p
import { Config, createApp, displayServerURL } from '@foal/core';
import { Config, createApp, Logger, ServiceManager } from '@foal/core';

// App
import { AppController } from './app/app.controller';
Expand All @@ -10,10 +10,13 @@ import { dataSource } from './db';
async function main() {
await dataSource.initialize();

const app = await createApp(AppController);
const serviceManager = new ServiceManager();
const logger = serviceManager.get(Logger);

const app = await createApp(AppController, { serviceManager });

const port = Config.get('port', 'number', 3001);
app.listen(port, () => displayServerURL(port));
app.listen(port, () => logger.info(`Listening on port ${port}...`));
}

main()
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/common/utils/display-server-url.util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Display server URL in console
*
* This function is deprecated. Use "services.get(Logger).info(`Listening on port ${port}...`)" instead.
*
* @deprecated
*/
export function displayServerURL(port: number, log = console.log) {
log();
log('\x1b[32m -------------------------------------- \x1b[0m');
Expand Down
9 changes: 6 additions & 3 deletions packages/examples/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import 'source-map-support/register';

// 3p
import { Config, createApp, displayServerURL } from '@foal/core';
import { Config, createApp, Logger, ServiceManager } from '@foal/core';

// App
import { AppController } from './app/app.controller';
Expand All @@ -16,10 +16,13 @@ import { dataSource } from './db';
async function main() {
await dataSource.initialize();

const app = await createApp(AppController);
const serviceManager = new ServiceManager();
const logger = serviceManager.get(Logger);

const app = await createApp(AppController, { serviceManager });

const port = Config.get('port', 'number', 3001);
app.listen(port, () => displayServerURL(port));
app.listen(port, () => logger.info(`Listening on port ${port}...`));
}

main()
Expand Down

0 comments on commit 3d5c845

Please sign in to comment.