2
0

main.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import * as helmet from 'helmet';
  2. import { NestFactory } from '@nestjs/core';
  3. import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
  4. import { AppModule } from './app.module';
  5. import { json } from 'body-parser';
  6. const hyperlinker = require('hyperlinker');
  7. /*
  8. Milvus insight API server bootstrap function
  9. */
  10. async function bootstrap() {
  11. // by default the server will be listening on port 3000
  12. const port = 3000;
  13. // create the nest application with Cross-origin resource sharing
  14. const app = await NestFactory.create(AppModule, { cors: true });
  15. // security patches
  16. app.use(helmet());
  17. // set upload file size limit
  18. app.use(json({ limit: '150mb' }));
  19. // add an API prefix
  20. app.setGlobalPrefix('/api/v1');
  21. // prepare swagger config
  22. const config = new DocumentBuilder()
  23. .setTitle('Milvus insight')
  24. .setVersion('1.0')
  25. .build();
  26. // create swagger document
  27. const document = SwaggerModule.createDocument(app, config);
  28. // set up API
  29. SwaggerModule.setup('api', app, document);
  30. // start listening
  31. await app.listen(port);
  32. // output server info
  33. require('dns').lookup(require('os').hostname(), (err, add, fam) => {
  34. // get link
  35. // add = `127.0.0.1`;
  36. const link = `http://${add}:${port}/api`;
  37. const blue = `\x1b[34m%s\x1b[0m`;
  38. const light = '\x1b[1m%s\x1b[0m';
  39. console.log(blue, '\n Milvus insight server started.');
  40. console.log(
  41. light,
  42. ` View the API docs on ${hyperlinker(link, link)} \n`,
  43. );
  44. });
  45. }
  46. // Start the server
  47. bootstrap();