#server #spa #simple #http-server #cli

app microserver

Simple ad-hoc server with SPA support based on Warp!. Excellent for testing React, Angular, Vue apps and the like.

10 releases

0.2.0 Nov 23, 2020
0.1.8 Aug 17, 2020
0.1.7 Jan 27, 2020
0.1.6 Dec 24, 2019
0.1.2 Oct 28, 2018

#52 in HTTP server

Download history 27/week @ 2020-11-02 37/week @ 2020-11-09 41/week @ 2020-11-16 90/week @ 2020-11-23 58/week @ 2020-11-30 44/week @ 2020-12-07 33/week @ 2020-12-14 31/week @ 2020-12-21 40/week @ 2020-12-28 51/week @ 2021-01-04 43/week @ 2021-01-11 51/week @ 2021-01-18 49/week @ 2021-01-25 52/week @ 2021-02-01 55/week @ 2021-02-08 116/week @ 2021-02-15

178 downloads per month

MIT license

15KB
108 lines

microserver

Actions Status Crates.io Docker Build Docker Pulls

Simple ad-hoc server with SPA support based on Warp! Excellent for testing React, Angular, Vue apps and the like.

Installation

You can compile it yourself:

cargo install microserver

or you can download the executable from Github releases and add it to your path.

Usage

No argument is mandatory so the current folder will be used as default if no path is specified

microserver

you can, of course, set the path of the folder you want to be served, by default in port 9090.

microserver ./path/to/folder

Need help?

microserver -h

Changing the address

# by default microserver will use 0.0.0.0
microserver -a 127.0.0.1

Changing the port

# by default microserver will use 9090 port
microserver -p 3000

SPA support

SPA support is enabled by default, meaning that if a resource is not found traffic will always be redirected to index.html.

If you want to opt-out of this behavior just use the --no-spa flag.

In the case you ever need to change the default spa index you can provide the --spa-index flag.

Docker

There are several ways to use microserver with a Docker image:

With a Dockerfile like the following:

# please omit the version if you just want the latest
FROM robertohuertasm/microserver:v0.1.6
# public being the location of your app files
COPY public/ /app/

You can then run your SPA / static site using:

$ docker build -t my-service:local .
$ docker run -p 9090:9090 my-service:local
MicroServer running on port 9090!
Serving /app
Spa support: true. Root: index.html

Alternatively, you could mount a volume with your content:

docker run -p 9090:9090 -v $(pwd)/public:/app robertohuertasm/microserver:v0.1.6

More complex Dockerfile usage example with a multi-stage build of a React SPA:

FROM node:10.18-stretch-slim as builder
WORKDIR /app
COPY ./ /app
RUN yarn
RUN yarn build

FROM robertohuertasm/microserver:v0.1.6
COPY --from=builder /app/public /app/

If you don't want the default arguments

In this case whenever you run the microserver image, you'll have to be explicit about the arguments:

# don't forget to add "/app" as your final argument
docker run -p 9090:9090 -v $(pwd)/public:/app robertohuertasm/microserver:v0.1.6 "/microserver" "--no-spa" "/app"

Dependencies

~13MB
~258K SLoC