Skip to content

Commit ed4b6fa

Browse files
committed
Build export as an extension of mu-javascript-template v1.0.0
1 parent 6964bf3 commit ed4b6fa

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

README.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ Export JS Template
33

44
Microservice to export data using custom defined SPARQL queries.
55

6-
76
## Using the template
8-
Extend the `semtech/mu-export-js-template` and add an export configuration in `/config/queries.js`.
7+
Run the `semtech/mu-export-js-template` service and mount an export configuration in `/config/export.js`.
98

10-
The configuration file defines an array of export configuration objects as follows:
9+
The `export.js` file defines an array of export configuration objects as follows:
1110

1211
```javascript
1312
export default [
1413
{
15-
path: '/all',
14+
path: '/example',
1615
format: 'text/csv',
17-
file: 'export-100.csv',
18-
query: `SELECT * FROM <http://mu.semte.ch/application> WHERE { ?s ?p ?o } LIMIT 100`
16+
query: `SELECT * FROM <http://mu.semte.ch/application> WHERE { ?s ?p ?o } LIMIT 100`,
17+
file: 'export-example.csv'
1918
},
2019
...
2120
];
@@ -24,14 +23,21 @@ export default [
2423

2524
An export configuration object consists of the following properties:
2625
* [REQUIRED] `path`: endpoint on which the export will be exposed
27-
* [REQUIRED] `format`: format of the export (`application/json`, `text/csv`, etc.)
28-
* [OPTIONAL] `file`: name of the attachment file containing the export. If no filename is provided, the export will be displayed inline in the browser.
26+
* [REQUIRED] `format`: format of the export (`application/json`, `text/csv`, `text/turtle`, etc.)
2927
* [REQUIRED] `query`: the SPARQL query to execute. This may be a `SELECT` or a `CONSTRUCT` query.
30-
31-
## Example Dockerfile
32-
33-
```
34-
FROM semtech/mu-export-js-template:1.0.0
35-
MAINTAINER Erika Pauwels <erika.pauwels@gmail.com>
36-
COPY queries.js /config
28+
* [OPTIONAL] `file`: name of the downloaded file. The filename may also be provided through a query param on the export request (e.g. `/example?file=my-name.csv`). If no filename is provided, the export will be displayed inline in the browser.
29+
30+
## Example docker-compose
31+
32+
```yaml
33+
version: '2',
34+
services:
35+
export:
36+
image: semtech/mu-export-js-template:0.2.0
37+
volumes:
38+
- ./:/config
39+
links:
40+
- database:database
3741
```
42+
43+
Note: if you extend the `semtech/mu-export-js-template` with an `export.js` file instead of mounting a volume in `/config`, the `ONBUILD` commands of the `semtech/mu-javascript-template` will not be executed in your image since `ONBUILD` is only executed one level deep.

app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { app } from 'mu';
22
import request from 'request';
33

4-
import queries from '/config/queries';
4+
import queries from '/config/export';
55

66
queries.map(function(config) {
77
app.get(config.path, function(req, res, next) {
@@ -23,7 +23,8 @@ queries.map(function(config) {
2323
console.error(`Something went wrong executing the SPARQL query: ${JSON.stringify(error)}`);
2424
next(error);
2525
} else if (response.statusCode == 200) {
26-
if (config.file) { res.attachment(config.file); }
26+
const filename = req.query.file || config.file;
27+
if (filename) { res.attachment(filename); }
2728
res.send(body);
2829
} else {
2930
next(new Error(body));

0 commit comments

Comments
 (0)