index.js 742 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. import {Server, ServerCredentials} from '@grpc/grpc-js';
  3. import {Config} from './env';
  4. import logger from './logger';
  5. import {MarkdownService} from './protocols/morus_grpc_pb';
  6. import { to_html } from './services/markdown';
  7. function main() {
  8. const args = process.argv;
  9. if(args.length !== 3){
  10. logger.error(`USAGE: node ${args[1]} CONFIG_FILE`);
  11. return;
  12. }
  13. const config = new Config("config.json");
  14. logger.info(`start gRPC server on http://0.0.0.0:${config.port}`);
  15. var server = new Server();
  16. server.addService(MarkdownService, {toHtml: to_html});
  17. server.bindAsync(`0.0.0.0:${config.port}`, ServerCredentials.createInsecure(), ()=>{
  18. server.start();
  19. });
  20. }
  21. main();