Jonathan Solorzano
Jonathan Solorzano

Reputation: 7022

Install jsreport in the application server

Can jsreport be hosted on the same server where the application is being executed?

jsreport website has this schema to describe how it should work:

onprem-schema

I've installed jsreport in the app server, and added the following code to the app: app-server

Code:

var jsreport   = require( 'jsreport' );
jsreport.bootstrapper().start();

And the following two messages are the ones I have doubts about:

2015-11-25T05:39:17.346Z - info: Creating default express app.
2015-11-25T05:39:17.495Z - info: jsreport server successfully started on http port: 61070

First, is it running another express app?(I already have an express app), Second, my app is running under port 3000, Why does it started on other port?

Also, if someone could give an explanation of the correct way to install it and run it, and also an example of how to make an endpoint for a report to be called from the client side of my app, I'll thank you...

Upvotes: 2

Views: 1197

Answers (1)

Jan Blaha
Jan Blaha

Reputation: 3095

From the documentation:

Attach to existing express app

If the jsreport contains express extension it will automatically start a default express.js based server running on ports specified in config. This behavior can be overridden with passing express application instance to the options. In this case jsreport express extension will just add required routes and middle-wares to the passed instance.

var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Hello from the main application');
});

var reportingApp = express();
app.use('/reporting', reportingApp);

var server = app.listen(3000);

var jsreport = require('jsreport')({
  express: { app :reportingApp, server: server },
  appPath: "/reporting"
});

jsreport.init().catch(function (e) {
  console.error(e);
});

See the docs for other answers.

Upvotes: 4

Related Questions