UNPKG

3.77 kBMarkdownView Raw
1# jsreport-express
2[![NPM Version](http://img.shields.io/npm/v/jsreport-express.svg?style=flat-square)](https://npmjs.com/package/jsreport-express)
3[![Build Status](https://travis-ci.org/jsreport/jsreport-express.png?branch=master)](https://travis-ci.org/jsreport/jsreport-express)
4
5> jsreport extension adding API and studio
6
7`jsreport-express` is the main extension you need when you want to add jsreport studio or API. Many other extensions works in conjunction with `jsreport-express` and extends studio ui or API. Just to name some of them:
8
9- [jsreport-templates](https://github.com/jsreport/jsreport-templates)
10- [jsreport-data](https://github.com/jsreport/jsreport-data)
11- [jsreport-scripts](https://github.com/jsreport/jsreport-scripts)
12- [jsreport-statistics](https://github.com/jsreport/jsreport-statistics)
13- [jsreport-authentication](https://github.com/jsreport/jsreport-authentication)
14
15And many others. Where some of them are working also without `jsreport-express` and some of them doesn't. This extension is designed to be just a wrapper for ui and it doesn't work standalone. The minimal configuration requires at least [jsreport-templates](https://github.com/jsreport/jsreport-templates) to be installed.
16
17## jsreport-core
18The following example shows how to start jsreport studio through express extension.
19```js
20var jsreport = require('jsreport-core')();
21jsreport.use(require('jsreport-templates')());
22jsreport.use(require('jsreport-express')({ httpPort: 2000}));
23
24jsreport.init();
25```
26
27### Attach to existing express app
28`jsreport-express` by default creates a new express.js application and starts to listen on specified port. In some cases you may rather use your own express.js app and just let `jsreport-express` to add specific routes to it. This can be done in the following way:
29```js
30var express = require('express');
31
32var app = express();
33
34app.get('/', function (req, res) {
35 res.send('Hello from the main application');
36});
37
38var reportingApp = express();
39app.use('/reporting', reportingApp);
40
41var jsreport = require('jsreport-core')();
42jsreport.use(require('jsreport-templates')());
43jsreport.use(require('jsreport-express')({ app: reportingApp }));
44
45jsreport.init();
46app.listen(3000);
47```
48
49## jsreport
50You can use the same technique in the full distribution of jsreport or with the auto discovered extensions:
51```js
52var express = require('express');
53var app = express();
54
55app.get('/', function (req, res) {
56 res.send('Hello from the main application');
57});
58
59var reportingApp = express();
60app.use('/reporting', reportingApp);
61
62var jsreport = require('jsreport')({
63 extensions: {
64 express: { app: reportingApp }
65 }
66});
67
68jsreport.init();
69app.listen(3000);
70```
71
72## Configuration
73
74`jsreport-express` uses some options from the global configuration:
75
76`httpPort` (number) - http port on which is jsreport running, if both httpPort and httpsPort are specified, jsreport will automaticaly create http redirects from http to https, if any of httpPort and httpsPort is specified default process.env.PORT will be used
77
78`httpsPort` (number) - https port on which jsreport is running
79
80`appPath` (string) - optionally set application path, if you run application on http://appdomain.com/reporting then set "/reporting" to `appPath`. The default behavior is that it is assumed that jsreport is running behind a proxy, so you need to do url url rewrite /reporting -> / to make it work correctly, See `mountOnAppPath` when there is no proxy + url rewrite involved in your setup.
81
82`mountOnAppPath` (boolean) - use this option along with `appPath`. it specifies if all jsreport routes should be available with appPath as prefix, therefore making `appPath` the new root url of application
83
84`certificate` object - path to key and cert file used by https