Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14.16.1-alpine
FROM node:16.16-alpine

LABEL maintainer="[email protected]"

Expand All @@ -8,6 +8,9 @@ ENV MU_SPARQL_ENDPOINT 'http://database:8890/sparql'
ENV MU_APPLICATION_GRAPH 'http://mu.semte.ch/application'
ENV NODE_ENV 'production'

ENV HOST '0.0.0.0'
ENV PORT '80'

ENV LOG_SPARQL_ALL 'true'
ENV DEBUG_AUTH_HEADERS 'true'

Expand All @@ -19,6 +22,8 @@ COPY . /usr/src/app
RUN chmod +x /usr/src/app/run-development.sh
RUN chmod +x /usr/src/app/build-production.sh

EXPOSE ${PORT}

CMD sh boot.sh

# This stuff only runs when building an image from the template
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ The following environment variables can be configured:

- `NODE_ENV` (default: `production`): either `"development"` or `"production"`. The environment to start the application in. The application live reloads on changes in `"development"` mode.
- `MAX_BODY_SIZE` (default: `100kb`): max size of the request body. See [ExpressJS documentation](https://expressjs.com/en/resources/middleware/body-parser.html#limit).
- `HOST` (default: `0.0.0.0`): The hostname you want the service to bind to.
- `PORT` (default: `80`): The port you want the service to bind to


### Mounting `/config`
You may let users extend the microservice with code.
Expand Down Expand Up @@ -196,3 +199,20 @@ When running inside a mu.semte.ch stack, you could mount your sources and connec
- /absolute/path/to/your/sources/:/app/
```
Now open Chromium, and visit [chrome://inspect/](chrome://inspect/). Once the service is launched, a remote target on localhost should pop up.

## Handling Delta's
If you are building a reactive service that should execute certain logic based on changes in the database, you want to hook it up to the [delta-notifier](https://github.com/mu-semtech/delta-notifier/). Some extra steps need to be taken to properly handle delta's, specifically the route handling delta's will need to use a specific bodyParser.

The default bodyParser provided by the template will only accept `application/vnd.api+json` and the delta-notifier is sending `application/json` content. Aside from that the body of a delta message may be very large, often several megabytes. By specifying the bodyParser on the route accepting delta messages you can easily modify it when required.

An example
```js
// app.js
import bodyParser from 'body-parser';
// ...

app.post("/delta-updates", bodyParser.json({limit: '50mb'}), async function(req, res) {
//...
}
```

6 changes: 4 additions & 2 deletions helpers/mu/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import bodyParser from 'body-parser';

var app = express();

var port = process.env.PORT || '80';
var hostname = process.env.HOST || '0.0.0.0';
var bodySizeLimit = process.env.MAX_BODY_SIZE || '100kb';

// parse JSONAPI content type
Expand Down Expand Up @@ -35,8 +37,8 @@ const errorHandler = function(err, req, res, next) {
};

// start server
app.listen( 80, function() {
console.log(`Starting server on port 80 in ${app.get('env')} mode`);
app.listen( port, hostname, function() {
console.log(`Starting server on ${hostname}:${port} in ${app.get('env')} mode`);
});

export default app;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@babel/preset-env": "^7.14.1",
"@babel/preset-typescript": "^7.16.7",
"babel-plugin-module-resolver": "4.1.0",
"body-parser": "~1.19.0",
"body-parser": "~1.20.0",
"coffeescript": "^2.6.1",
"env-var": "^7.0.0",
"express": "^4.17.1",
Expand Down