Skip to content

Commit

Permalink
feat: add improvements to the http server (#65)
Browse files Browse the repository at this point in the history
* chore(main): Add graceful shutdown to the http service

* build(compose): add a health check to the compose file

* build(main): rename the temporary path environment variable

* build(make): add changes to the makefile

* fix(templates): fix zip files preview

* fix(docker): add non-root user to the dockerfile

* fix(templates): shorten the modal title

* build(make): set the build target as prerequisite

* feat(main): add api router

* refactor(main): refactor the functions and handlers that are responsible to convert input files

* docs(README): add documentation on how to use the api
  • Loading branch information
danvergara authored Sep 20, 2024
1 parent 1d52b49 commit 86123de
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 122 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ COPY --from=builder /usr/share/fonts /usr/share/fonts

ENV FONTCONFIG_PATH /usr/share/fonts

# Use morphos as user
RUN useradd -m morphos
USER morphos

EXPOSE 8080

ENTRYPOINT ["/bin/morphos"]
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
HTMX_VERSION=1.9.6
RESPONSE_TARGETS_VERSION=1.9.11
BOOTSTRAP_VERSION=5.3.2
GO_VERSION=1.21.5

.PHONY: run
## run: Runs the air command.
Expand All @@ -27,11 +26,11 @@ download-bootstrap:
.PHONY: docker-build
## docker-build: Builds the container image
docker-build:
docker build --build-arg="GO_VERSION=${GO_VERSION}" -t morphos .
docker build -t morphos .

.PHONY: docker-run
## docker-run: Runs the container
docker-run:
docker-run: docker-build
docker run --rm -p 8080:8080 -v /tmp:/tmp morphos

.PHONY: help
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ docker run --rm -p 8080:8080 -v /tmp:/tmp ghcr.io/danvergara/morphos-server:late

## Usage

### HTML form

Run the server as mentioned above and open up your favorite browser. You'll see something like this:

<img src="screenshots/morphos.png"/>
Expand All @@ -68,6 +70,43 @@ A modal will pop up with a preview of the converted image.

<img src="screenshots/modal_morphos.png"/>

### API

You can consume morphos through an API, so other systems can integrate with it.

##### Endpoints

`GET /api/v1/formats`

This returns a JSON that shows the supported formats at the moment.

e.g.

```
{"documents": ["docx", "xls"], "image": ["png", "jpeg"]}
```

`POST /api/v1/upload`

This is the endpoint that converts files to a desired format. It is basically a multipart form data in a POST request. The API simply writes the converted files to the response body.

e.g.

```
curl -F 'targetFormat=epub' -F 'uploadFile=@/path/to/file/foo.pdf' localhost:8080/api/v1/upload --output foo.epub
```
The form fields are:

* targetFormat: the target format the file will be converted to
* uploadFile: The path to the file that is going to be converted

### Configuration

The configuration is only done by the environment varibles shown below.

* `MORPHOS_PORT` changes the port the server will listen to (default is `8080`)
* `MORPHOS_UPLOAD_PATH` defines the temporary path the files will be stored on disk (default is `/tmp`)

## Supported Files And Convert Matrix

### Images X Images
Expand Down
22 changes: 16 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
name: morphos
services:
morphos-server:
ports:
- 8080:8080
volumes:
- /tmp:/tmp
image: ghcr.io/danvergara/morphos-server:latest
morphos-server:
image: ghcr.io/danvergara/morphos-server:latest
# uncomment this if you want to build the container yourself.
# build:
# context: .
# target: release
ports:
- 8080:8080
volumes:
- /tmp:/tmp
healthcheck:
test: timeout 10s bash -c ':> /dev/tcp/127.0.0.1/8080' || exit 1
interval: 60s
retries: 3
start_period: 20s
timeout: 30s
Loading

0 comments on commit 86123de

Please sign in to comment.