Skip to content

Commit

Permalink
Merge branch 'fix/repeatable-build' of github.com:ONSdigital/mathjax-api
Browse files Browse the repository at this point in the history
  • Loading branch information
janderson2 committed Dec 3, 2024
2 parents 2d1d632 + 7edf63d commit da40553
Show file tree
Hide file tree
Showing 8 changed files with 2,214 additions and 35 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v4.8.1
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:4
FROM node:4.8.1

WORKDIR /src
ADD . /src
Expand Down
9 changes: 9 additions & 0 deletions LICENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) Crown Copyright (Office for National Statistics)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
NVM_SOURCE_PATH ?= $(HOME)/.nvm/nvm.sh

ifneq ("$(wildcard $(NVM_SOURCE_PATH))","")
NVM_EXEC = source $(NVM_SOURCE_PATH) && nvm exec --
endif
NPM = $(NVM_EXEC) npm
NODE = $(NVM_EXEC) node

.PHONY: all
all: audit test build

.PHONY: audit
audit:
# $(NPM) audit --audit-level=high
@echo audit not yet implemented for this repo
exit 1

.PHONY: build
build:
$(NPM) install

.PHONY: debug
debug: build
$(NODE) app.js

.PHONY: test
test:
@echo tests not yet implemented for this repo
exit 1
72 changes: 57 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,69 @@
# mathjax-api
A Node.js HTTP API to render MathJax equations in HTML content

This service uses the MathJax-node implementation that is optimised for mathjax embedded in HTML content. It is currently limited to LaTex to SVG conversion, but feel free to extend it :)
A Node.js HTTP API to render MathJax equations in HTML content.

Defaults port 8080.
This service uses the MathJax-node implementation that is optimised for mathjax embedded in HTML content. It is currently limited to Tex to SVG conversion.

Node usage:
```
$ npm install
$ node app.js
```
## Getting started

Test the server is working by doing a HTTP GET or navigate to http://localhost:8080
### Prerequisites

```
$ curl http://localhost:8080
```
To run the API locally you must have the following:

To post content to the service for conversion, put your content in the "input" field using a application/x-www-form-urlencoded format:
1. [nvm](https://github.com/nvm-sh/nvm) installed:

```shell
brew install nvm
```

Then add the following to your `~/.bashrc` or `~/.zshrc`:

```shell
export NVM_DIR="$HOME/.nvm"
[ -s "$(brew --prefix nvm)/nvm.sh" ] && \. "$(brew --prefix nvm)/nvm.sh"
[ -s "$(brew --prefix nvm)/etc/bash_completion.d/nvm" ] && \. "$(brew --prefix nvm)/etc/bash_completion.d/nvm"
```

and reload your shell:

```shell
exec $SHELL -l
```

2. The node version specified in [`.nvmrc`](./.nvmrc) installed through nvm:

```shell
nvm install
```

### Build and run

Once you have node installed, run the following to install the dependencies and run the server:

```shell
make debug
```
$ curl --data "input=$ \\Gamma(z) = \\int_0^\\infty t^{z-1} $" http://localhost:8080
```

The API binds to port 8080, and is currently not configurable.

### Test the API is running

To test the API is running correctly:

1. Test the server is working by doing a HTTP GET or navigate to http://localhost:8080:

```shell
curl http://localhost:8080
```

2. Test `POST`ing content to the service for conversion:

```shell
curl -X POST -H "Content-Type: text/plain" --data "input=$ Gamma(z) = int_0^infty t^{z-1} $" http://localhost:8080
```

## Licence

Copyright © Crown Copyright ([Office for National Statistics](https://www.ons.gov.uk))

Released under MIT license, see [LICENCE](LICENCE.md) for details.
Loading

0 comments on commit da40553

Please sign in to comment.