Giter VIP home page Giter VIP logo

serve's Introduction

serve is a static http server anywhere you need one.

Mentioned in Awesome Go

codecov Go Report Card Go Reference

GitHub Release Docker Pulls

🚨 The main branch is currently in active R&D for the next release of serve. To use serve, please be sure to download a previous release as no stability guarantees are being made furter progress has been made towards a release candidate.

TL;DR

It's basically python -m SimpleHTTPServer 8080 written in Go, because who can remember that many letters?

Features

  • HTTPS (TLS)
  • CORS support
  • Request logging
  • net/http compatible
  • Support for BasicAuth via users.json

Installation

serve can be installed in a handful of ways:

Homebrew on macOS

If you are using Homebrew on macOS, you can install serve with the following command:

brew install syntaqx/tap/serve

Docker

The official syntaqx/serve image is available on Docker Hub.

To get started, try hosting a directory from your docker host:

docker run -v .:/var/www:ro -d syntaqx/serve

Alternatively, a simple Dockerfile can be used to generate a new image that includes the necessary content:

FROM syntaqx/serve
COPY . /var/www

Place this in the same directory as your content, then build and run the container:

docker build -t some-content-serve .
docker run --name some-serve -d some-content-serve

Exposing an external port

docker run --name some-serve -d -p 8080:8080 some-content-serve

Then you can navigate to http://localhost:8080/ or http://host-ip:8080/ in your browser.

Using environment variables for configuration

Currently, serve only supports using the PORT environment variable for setting the listening port. All other configurations are available as CLI flags.

In future releases, most configurations will be settable from both the CLI flag as well as a compatible environment variable, aligning with the expectations of a 12factor app. But, that will require a fair amount of work before the functionality is made available.

Here's an example using docker-compose.yml to configure serve to use HTTPS:

version: '3'
services:
  web:
    image: syntaqx/serve
    volumes:
      - ./static:/var/www
      - ./fixtures:/etc/ssl
    environment:
      - PORT=1234
    ports:
      - 1234
    command: serve -ssl -cert=/etc/ssl/cert.pem -key=/etc/ssl/key.pem -dir=/var/www

The project repository provides an example docker-compose that implements a variety of common use-cases for serve. Feel free to use those to help you get started.

Download the binary

Quickly download install the latest release:

curl -sfL https://install.goreleaser.com/github.com/syntaqx/serve.sh | sh

Or manually download the latest release binary for your system and architecture and install it into your $PATH.

From source

To build from source, check out the instructions on getting started with development.

Usage

serve [options] [path]

[path] defaults to . (relative path to the current directory)

Then simply open your browser to http://localhost:8080 to view your server.

Options

The following configuration options are available:

  • --host host address to bind to (defaults to 0.0.0.0)
  • --port listening port (defaults to 8080)
  • --ssl enable https (defaults to false)
  • --cert path to the ssl cert file (defaults to cert.pem)
  • --key path to the ssl key file (defaults to key.pem)
  • --dir directory path to serve (defaults to ., also configurable by arg[0])
  • --users path to users file (defaults to users.dat); file should contain lines of username:password in plain text

Development

To develop serve or interact with its source code in any meaningful way, be sure you have the following installed:

Prerequisites

Install

You can download and install the project from GitHub by simply running:

git clone [email protected]:syntaqx/serve.git && cd $(basename $_ .git)
make install

This will install serve into your $GOPATH/bin directory, which assuming is properly appended to your $PATH, can now be used:

$ serve version
serve version v0.0.6-8-g5074d63 windows/amd64

Using serve manually

Besides running serve using the provided binary, you can also embed a serve.FileServer into your own Go program:

package main

import (
    "log"
    "net/http"

    "github.com/syntaqx/serve"
)

func main() {
    fs := serve.NewFileServer()
    log.Fatal(http.ListenAndServe(":8080", fs))
}

License

serve is open source software released under the MIT license.

As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).

As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.

serve's People

Contributors

dependabot[bot] avatar filego avatar github-actions[bot] avatar imgbotapp avatar jsoref avatar syntaqx avatar tisba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

serve's Issues

Enable dependabot

Enable dependabot for the repository!

Look into what other OSS projects are doing to keep their code updated, but also not be super annoying to everyone.

Feature Request: Status Codes to logs

It would be nice to see the status code in the logs, e.g.:

~ » serve
[serve] 2019/01/28 19:59:17 http server listening at 0.0.0.0:8080
[serve] 2019/01/28 19:59:28 GET /i-do-not-exist [::1]:49835 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36

I was looking at our statically build website and one resource could not be loaded - impossible to sport with serve's logs currently :)

Suggest

Can user authentication be added?

HTTP methods

Hello,

serve response contains header

access-control-allow-methods: HEAD, OPTIONS, GET, POST, PUT, PATCH, DELETE

but it isn't clear how to get key/value posted via POST method on the server side.

Could please clarify this?

Migrate from Travis to GitHub Actions

Provide multiple asynchronous workflows to replace the CI & CD that's currently provided by Travis:

  • go test
  • go modules && verification
  • golangci-lint
  • goreleaser

Don't forget to remove .travis.yml and update the readme shield

Support for MIME types as option

I would like to see the headers like "application/javascript" in the .js file.
Some problems like Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec. (from chrome) could occur, so I'm willing to get this feature. Thank you for creating this, I used a lot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.