index.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { queryService } from "./services/query.service";
  2. const express = require('express');
  3. const bodyParser = require('body-parser');
  4. const Messages = require('./schemas/message');
  5. const app = express();
  6. const mongoose = require('mongoose');
  7. app.use(bodyParser.urlencoded({ extended: false }))
  8. app.use(bodyParser.json());
  9. mongoose.connect('mongodb://192.168.100.59:27017/fromEnzo', { useNewUrlParser: true, useUnifiedTopology: true })
  10. .then(() => console.log('Database connected'))
  11. .catch(err => console.log(err));
  12. /* Express Server: Http Connection */
  13. // const port = process.env.PORT || 3000;
  14. // app.listen(port, () => {
  15. // console.log(`Server listening on port http://localhost:${port}`);
  16. // });
  17. // GRPC SIDE
  18. const grpc = require('grpc');
  19. const protoLoader = require('@grpc/proto-loader');
  20. const packageDefinition = protoLoader.loadSync('hello.proto');
  21. const greeterProto = grpc.loadPackageDefinition(packageDefinition).Greeter;
  22. function sayHello(call, callback) {
  23. callback(null, { message: 'Hello, ' + call.request.name });
  24. }
  25. const server = new grpc.Server();
  26. server.addService(greeterProto.service, { sayHello });
  27. server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
  28. server.start();