SkillAgentSearch skills...

Goserve

Distributable HTTP server with your mock HTMLs

Install / Use

/learn @kazuma1989/Goserve
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

goserve

goserve is a distributable HTTP server for your HTMLs.

It is just a small single file with no configuration but gives your HTMLs the power of http: protocol instead of file: protocol.

Basic usage

Place a goserve binary into your directory and run to show your HTMLs under the directory.

BEFORE (without goserve):

 example/
 ├── index.html
 └── message.json

Run open index.html (or just double click to open index.html), you will see:

AFTER (with goserve for macOS):

 example/
+├── goserve-mac
 ├── index.html
 └── message.json

Run ./goserve-mac (or just double click to start goserve.exe when you use Windows), you will see:

Config

Routing (mapping between a URL and a file path)

Add goserve.json in the directory where goserve exists.

 example/
+├── goserve.json
 ├── goserve-mac
 ├── index.html
 └── message.json
{
  "route": {
    "/api/(.*)": "$1.json"
  }
}

You can see the content of message.json at http://localhost:8080/api/message in addition to http://localhost:8080/message.json.

Change port

 {
+  "port": 8000,
   "route": {
     "/api/(.*)": "$1.json"
   }
 }

Redirect

 {
   "port": 8000,
+  "redirect": {
+    "/home": "/"
+  },
   "route": {
     "/api/(.*)": "$1.json"
   }
 }

Routing based on a posted JSON

Refer to JSON values by JSONPath syntax.

 {
   "port": 8000,
   "redirect": {
     "/home": "/"
   },
   "route": {
     "/api/(.*)": "$1.json",
+    "/post": "{$.name}.json"
   }
 }

Posting {"name":"foo"} to /post, you get the content of foo.json.

Development

Requirements

To build goserve from the source, you need:

View on GitHub
GitHub Stars4
CategoryDevelopment
Updated1y ago
Forks0

Languages

Go

Security Score

60/100

Audited on Oct 23, 2024

No findings