Error occured during reporter init Error (trying to attach socket.io)



  • Hi Every one! How I'll solve this:

    info: fs store is initialized successfully
    2020-08-12T16:36:02.113Z - debug: studio default theme is: light
    2020-08-12T16:36:02.125Z - info: Configuring routes for existing express app.
    2020-08-12T16:36:02.154Z - info: Using existing server instance.
    2020-08-12T16:36:02.159Z - info: fs store emits sockets to synchronize underlying changes with studio
    2020-08-12T16:36:02.167Z - error: Error occured during reporter init Error: You are trying to attach socket.io to an express request handler function. Please pass a http.Server instance.
        at Server.listen.Server.attach (C:\_test\node_modules\socket.io\lib\index.js:258:11)
    
    • main.ts
    import { NestFactory } from '@nestjs/core';
    import { AppModule } from './app.module';
    import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
    import * as compression from 'compression';
    import configService from './application/config/configuration.service';
    import { WebModule } from './web/web.module';
    import { CommonsModule } from '@domain/commons/commons.module';
    import { Dynamic } from '@domain/dynamic/dynamic.entity';
    import { SecurityModule } from '@domain/security/security.module';
    import { json, urlencoded } from 'express';
    import * as  express from 'express';
    
    async function appNest() {
      const app = await NestFactory.create(AppModule, {
      })
      app.enableCors()
      app.use(compression())
      const options = new DocumentBuilder()
        .setTitle(`Nautilus Backend API`)
        .setDescription(`ERP`)
        .setVersion(`0.0.1`)
        .addBearerAuth()
        .build()
      return app
    }
    
    async function bootstrap() {
      const mainApp = express()
    
      async function mountSubApp(app, mountPath, subAppBoot) {
        const subApp = await subAppBoot()
        await subApp.init()
        app.use(mountPath, subApp.getHttpAdapter().getInstance())
        return app
      }
    
      const reportingApp = express();
      mainApp.use('/v1/reports', reportingApp);
    
      mountSubApp(mainApp, '', appNest)
        .then(app => app.listen(configService.httpServerPort))
    
      const jsreport = require('jsreport')({
        extensions: {
          express: { app: reportingApp, server: mainApp },
        },
      });
    
      jsreport.init().then(() => {
        console.log('jsreport server started')
      }).catch((e) => {
        console.error(e);
      });
    }
    bootstrap();
    
    • jsreport.config.json
    {
      "appPath": "/v1/reports",
      "store": {
        "provider": "fs"
      },
      "extensions": {
        "fs-store-aws-s3-persistence": {
          "accessKeyId": "xxx",
          "secretAccessKey": "xxx",
          "bucket": "bucket",
          "lock": {
            "queueName": "jsreport-lock.fifo"
          },
          "region": "us-east-1",
          "enabled": true,
          "attributes": {},
          "s3Options": {
            "maxRetries": 10
          }
        },
        "fs-store": {
          "persistence": {
            "provider": "aws-s3"
          },
          "compactionInterval": 60000
        },
        "studio": { "flushLogsInterval": 60000 },
        "scheduling": { "intreval": 60000 },
        "authentication": {
          "cookieSession": {
            "secret": "M5DnenXb~YpuUrUY"
          },
          "admin": {
            "username": "admin",
            "password": "123456"
          },
          "enabled": true
        },
        "sample-template": {
          "createSamples": false
        },
        "scripts": {
          "allowedModules": ["https"],
          "strategy": "http-server"
        }
      }
    }
    
    


  • Please see here
    https://jsreport.net/learn/adapting-jsreport#attach-to-existing-express-app

    const express = require('express');
    const app = express();
    
    app.get('/', (req, res) => {
      res.send('Hello from the main application');
    });
    
    const reportingApp = express();
    app.use('/reporting', reportingApp);
    
    const server = app.listen(3000);
    
    const jsreport = require('jsreport')({
      extensions: {
          express: { app: reportingApp, server: server },
      },
      appPath: "/reporting"
    });
    
    jsreport.init().then(() => {
      console.log('jsreport server started')
    }).catch((e) => {
      console.error(e);
    });
    

    The server prop from express: { app: reportingApp, server: mainApp } should be taken from the result of mainApp.listen()



  • Thank you so much for helping very quickly, Jan Blaha.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.