Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add improvements to the http server #65

Merged
merged 11 commits into from
Sep 20, 2024
Merged
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
Loading