github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/build-blockchain-insurance-app-master/web/www/app.js (about)

     1  'use strict';
     2  
     3  import { Server } from 'http';
     4  import express from 'express';
     5  import socketIo from 'socket.io';
     6  import configureExpress from './config/express';
     7  import shopRouter, { wsConfig as shopWsConfig }
     8    from './routers/shop.router';
     9  import policeRouter, { wsConfig as policeWsConfig }
    10    from './routers/police.router';
    11  import repairShopRouter, { wsConfig as repairShopWsConfig }
    12    from './routers/repair-shop.router';
    13  import insuranceRouter, { wsConfig as insuranceWsConfig }
    14    from './routers/insurance.router';
    15  
    16  const INSURANCE_ROOT_URL = '/insurance';
    17  const POLICE_ROOT_URL = '/police';
    18  const REPAIR_SHOP_ROOT_URL = '/repair-shop';
    19  const SHOP_ROOT_URL = '/shop';
    20  
    21  const app = express();
    22  const httpServer = new Server(app);
    23  
    24  // Setup web sockets
    25  const io = socketIo(httpServer);
    26  shopWsConfig(io.of(SHOP_ROOT_URL));
    27  policeWsConfig(io.of(POLICE_ROOT_URL));
    28  repairShopWsConfig(io.of(REPAIR_SHOP_ROOT_URL));
    29  insuranceWsConfig(io.of(INSURANCE_ROOT_URL));
    30  
    31  configureExpress(app);
    32  
    33  app.get('/', (req, res) => {
    34    res.render('home', { homeActive: true });
    35  });
    36  
    37  // Setup routing
    38  app.use(SHOP_ROOT_URL, shopRouter);
    39  app.use(POLICE_ROOT_URL, policeRouter);
    40  app.use(REPAIR_SHOP_ROOT_URL, repairShopRouter);
    41  app.use(INSURANCE_ROOT_URL, insuranceRouter);
    42  
    43  export default httpServer;