-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
15 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# mu-javascript-template | ||
# Mu Javascript template | ||
|
||
Template for writing mu.semte.ch services in JavaScript | ||
Template for writing mu.semte.ch services in JavaScript using [Express 4](https://expressjs.com/) | ||
|
||
## Getting started | ||
|
||
|
@@ -9,7 +9,7 @@ Create a new folder. Add the following Dockerfile: | |
FROM semtech/mu-javascript-template | ||
MAINTAINER Aad Versteden <[email protected]> | ||
|
||
Create your microservice: | ||
Create your microservice in `app.js`: | ||
|
||
import { app, query } from 'mu'; | ||
|
||
|
@@ -35,18 +35,22 @@ Create your microservice: | |
res.send( "Oops something went wrong: " + JSON.stringify( err ) ); | ||
}); | ||
} ); | ||
|
||
Check [Express' Getting Started guide](https://expressjs.com/en/starter/basic-routing.html) to learn how to build a REST API in Express. | ||
|
||
## Requirements | ||
|
||
- **database link**: You need a link to the `database` which exposes a sparql endpoint on `http://database:8890/sparql`. In line with other microservices. | ||
- **database link**: You need a link to the `database` which exposes a SPARQL endpoint on `http://database:8890/sparql`. In line with other microservices. | ||
|
||
## Imports | ||
|
||
The following importable variables are available: | ||
|
||
- `app`: The application on which routes can be added | ||
- `app`: The [Express application](https://expressjs.com/en/guide/routing.html) on which routes can be added | ||
- `query(query) => Promise`: Function for sending queries to the triplestore | ||
- `update(query) => Promise`: Function for sending updates to the triplestore | ||
- `uuid()` => string: Generates a random UUID | ||
- `sparql`: [Template tag](https://www.npmjs.com/package/sparql-client-2#using-the-sparql-template-tag) to create queries with interpolated values | ||
|
||
You can either import specific attributes from the mu library, or import the whole mu object. | ||
|
||
|
@@ -66,11 +70,15 @@ An example of importing the whole library: | |
res.send('Hello using full import'); | ||
} ); | ||
|
||
## Dependencies | ||
|
||
You can install additional dependencies by including a `package.json` file next to your `app.js`. It works as you would expect: just define the packages in the `dependencies` section of the `package.json`. They will be installed automatically at build time. | ||
|
||
## Developing with the template | ||
|
||
When developing, you can use the template image, mount the volume with your sources on `/app` and add a link to the database. | ||
When developing, you can use the template image, mount the volume with your sources on `/app` and add a link to the database. The service will live-reload on changes. You'll need to restart the container when you define additional dependencies in your `package.json`. | ||
|
||
dr run --link virtuoso:database \ | ||
docker run --link virtuoso:database \ | ||
-v `pwd`:/app \ | ||
-p 8888:80 \ | ||
--name my-js-test \ | ||
|