Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/poga/sitex

http server with support to Netlify's `_redirect` and `_headers`
https://github.com/poga/sitex

http-server netlify

Last synced: 3 months ago
JSON representation

http server with support to Netlify's `_redirect` and `_headers`

Awesome Lists containing this project

README

        

# SiteX

[![Go Report Card](https://goreportcard.com/badge/github.com/poga/sitex)](https://goreportcard.com/report/github.com/poga/sitex)
[![codecov](https://codecov.io/gh/poga/sitex/branch/master/graph/badge.svg)](https://codecov.io/gh/poga/sitex)
[![Build Status](https://travis-ci.org/poga/sitex.svg?branch=master)](https://travis-ci.org/poga/sitex)

A HTTP server with support to Netlify's [redirect and rewrite rules](https://www.netlify.com/docs/redirects/), [custom headers, and basic auth](https://www.netlify.com/docs/headers-and-basic-auth/).

**Note**: Since Netlify is a proprietary service. It's really hard to fully mimic Netlify's behavior. So most implementation here is based on guessing and intuition.

`go get -u github.com/poga/sitex`

## Usage

Define the redirect rules with `_redirects` file.

```
# redirect / to test.json
/ /test.json 200

# 301 redirect
/foo /test.json

# query params
/bar id=:id /test-:id.json

# proxy
/google https://google.com 200
```

You can also define custom headers and/or basic authentication with `_headers` file.

```
# A path:
/test.json
# Headers for that path:
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

# basic auth
/something/*
Basic-Auth: someuser:somepassword anotheruser:anotherpassword
```

Start SiteX server with `sitex` command.

```
$ sitex
```
Now you got a web server which:

* `http://localhost:8080/` will render `/test.json`
* `http://localhost:8080/test.json` will render the file
* `http://localhost:8080/foo` will redirect to `/test.json`
* `http://localhost:8080/bar?id=2` will render `/test-2.json`

## CLI options

* dir: the directory you want to server. **Default: current working directory**.
* port: port to listen. **Default: 8080**.

## Rules

**Note: Custom header is a paid-only feature on Netlify.**

See `_headers` and `_redirects` file in the `example` folder.

For detailed documents, see Netlify's [redirect document](https://www.netlify.com/docs/redirects/) and [header document](https://www.netlify.com/docs/headers-and-basic-auth/).

## Contribute

Feel free to open an issue if you find difference between SiteX and Netlify.

## License

The MIT License