Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/purarue/subpath-serve
a basic webserver to serve text files from a directory by matching subpaths
https://github.com/purarue/subpath-serve
dotfiles filesystem server
Last synced: 2 months ago
JSON representation
a basic webserver to serve text files from a directory by matching subpaths
- Host: GitHub
- URL: https://github.com/purarue/subpath-serve
- Owner: purarue
- License: mit
- Created: 2020-06-03T20:16:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-27T20:22:47.000Z (3 months ago)
- Last Synced: 2024-11-24T14:15:33.163Z (2 months ago)
- Topics: dotfiles, filesystem, server
- Language: Go
- Homepage: https://purarue.xyz/d/?dark
- Size: 43.9 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# subpath-serve
A small server used to serve text files from my [dotfiles](https://github.com/purarue/dotfiles) (though it could be used to serve any text files/folder).
Any request to `/...` tries to match against some file basepath from a root folder (defaults to `./serve`).
A request to the base path (`/`) without anything else returns a newline delimited list of everything in the `./serve` folder.
Does not build an index at build/initial server start, so the `./serve` folder can be modified while the server is running to change results; each request searches the folder for the query.
Appending `?dark` to the end of a URL converts a request to an HTML response with a dark theme, and converts the index to link to each page.
Appending `?redirect` to the end of the URL redirects to the corresponding `-git-http-prefix`, e.g.:
`.gitignore?redirect` ->
Example Requests:
-
-
-### matching strategy
An example of how this matches. If the files in `./serve` are:
```
./folder1/a
./folder2/a
./folder3/b
```| Request to | Resolves to |
| ---------- | ----------- |
| /a | ./folder1/a |
| /b | ./folder3/b |
| /folder2/a | ./folder2/a |It matches `./folder1/a` just because that's the one it found first, if there's a possibility of a conflict, its better to provide a unique subpath.
### Run
```sh
usage: subpath-serve [FLAG...]
For instructions, see https://github.com/purarue/subpath-serve-folder string
path to serve subpath-serve on (default "./serve")
-git-http-prefix string
Optionally, provide a prefix which when the matched filepath is appended to, links to a git web view (e.g. https://github.com/purarue/dotfiles/blob/master)
-port int
port to serve subpath-serve on (default 8050)
```As an example, you can use my dotfiles:
```
git clone "https://github.com/purarue/dotfiles.git" "./serve"
subpath-serve
``````
curl localhost:8050/rc.conf
```The response contains the `X-Filepath` header, which includes the full path to the matched file.
### Install
Install `golang`.
You can clone and run `go build`, or:
```
go install -v "github.com/purarue/subpath-serve@latest"
```which downloads, builds and puts the binary on your `$GOBIN`.