Sign inSign up

donatowolfisberg/spa-server

By donatowolfisberg

•Updated about 3 years ago

Image
0

2.1K

donatowolfisberg/spa-server repository overview

⁠Simple spa-server

Docker Build Image Version Image Size Docker Pulls

We have all been there. You create a small backend with a single-page-application frontend and want to deploy it. Then you create a nginx dockerfile and copy the nginx config you looked up 2 years ago from one of your other projects. This without really knowing much about it and besides having to run full-fledged nginx server running for really no good reason.

To solve this I created a small simple web server that does html5 routing. It does not come with the 99 features that you don't use. It is written in golang and utilizes the embed feature so that there is just a single binary in your final stage docker image.

It will send you the file if it finds it in the else it will send you the index.html file. This behavior is useful if you want to do client-side routing.

For example the empty image size of nginx is ~130MB in contrast the final build of the example in this repo is just 6.18MB.

⁠Example

There is an example setup in the ./example⁠ folder in this repository⁠.

⁠Usage

Create a "Dockerfile" where you start with the image "donatowolfisberg/spa-server". There you copy your application to the public folder. After you run the "build.sh" script. This bundles your frontend with the server into a single binary. In the next build-step start from "scratch" and copy your binary into the root path. At last, you need to add CMD ["server"] to get it started.

FROM donatowolfisberg/spa-server as builder

COPY public public
RUN ./build.sh

FROM scratch

COPY --from=builder /app/server /server
CMD ["/server"]

⁠Options

The following options can be configured through environment variables.

Env NameDefault
PORT8080
ADDRESS0.0.0.0
READ_TIMEOUT_SECONDS5
WRITE_TIMEOUT_SECONDS10
IDLE_TIMEOUT_SECONDS120

⁠Build local

docker build . -t spa-server 

Tag summary

Content type

Image

Digest

sha256:e356ed161…

Size

283.2 MB

Last updated

about 3 years ago

docker pull donatowolfisberg/spa-server