Emergency web server
Emergency web server
For those occasions when your webserver is down and you want to display a quick maintainance note. Or just want to quickly demo a static site. Or whatever :)
It can take a directory, a file or directly the body string. The -proxy flag can be useful when used as a development server.
…go get github.com/rif/spark$ spark message.html
$ spark "
Out of order
Working on it...
"
$ spark static_site/
$ spark -port 80 -sslPort 443 "
Ooops!
"
$ spark -deny ".git*,LICENSE" ~/go/rif/spark
$ spark -proxy "/api=>http://localhost:9090/api" .
$ spark -port 9000 -corsOrigin "https://www.mydomain.com" -contentType "application/json" '{"message":"Hello"}'The /echo endpoint returns request details (method, headers, body) for debugging:
$ spark "Hello" &
$ curl -X POST http://localhost:8080/echo -d '{"test": "data"}'Create mock API responses using directory structure:
# Directory structure defines endpoints
mock/
users/
GET # responds to GET /users
POST_201 # responds to POST /users with 201 status
api/
products/
GET # responds to GET /api/products
# Start mock server
$ spark -mock mock/
# Test endpoints
$ curl http://localhost:8080/users
$ curl -X POST http://localhost:8080/usersFiles are named after HTTP verbs (case-insensitive). Add _STATUS suffix for custom status codes (e.g., POST_201, DELETE_204). Returns 405 Method Not Allowed for unsupported methods.
To quickly generate a ssl certificate run:
go run $GOROOT/src/crypto/tls/generate_cert.go --host="localhost"No open issues yet, or sync has not completed.