https://github.com/kociumba/kserver
A fully customisable server written in go driven by YAML ⚙️ or dynamic LUA 🌕 configuration
https://github.com/kociumba/kserver
go golang lua server yaml
Last synced: about 2 months ago
JSON representation
A fully customisable server written in go driven by YAML ⚙️ or dynamic LUA 🌕 configuration
- Host: GitHub
- URL: https://github.com/kociumba/kserver
- Owner: kociumba
- License: mit
- Created: 2024-05-31T23:11:21.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-08T12:59:31.000Z (almost 2 years ago)
- Last Synced: 2025-03-15T10:30:48.504Z (over 1 year ago)
- Topics: go, golang, lua, server, yaml
- Language: Go
- Homepage:
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kserver
A proof of concept server that can be configured with YAML ⚙️ or LUA 🌕
## Usage
For YAML create a `kserver.yml` file in the directory you want to serve,
the file should look like this:
```yaml copy
# yaml-language-server: $schema=https://raw.githubusercontent.com/kociumba/kserver/main/.kserver
port: 8080
handlers:
- route: /
content: ./index.html
contentType: text/html
# Add more routes here, in VSCode you can use ctrl+space to autocomplete the array
```
>[!NOTE]
> There is a YAML schema availible if you include the top comment, which allows for autocomplete in VSCode.
> [!TIP]
>**To use lua configuration, pass the `-lua` flag to `kserver`**
>
>*There is no way to set the port in lua so you can use `-port: INT` to configure it or use the default `8000`*
For LUA create a `kserver.lua` file in the directory you want to serve,
the file should look like this:
```lua copy
local routes = {
-- It's important to keep the order of these parameteres otherwise the server will confuse them
{route = "/", content = "./index.html", contentType = "text/html"},
-- Add more routes here
}
Register_routes(routes)
```
If you need custom logic before registering you can add it before the call to Register_routes(routes) or replace it with this:
```lua copy
for i, r in ipairs(routes) do
local route = route.new(r.route, r.content, r.contentType, r.handler)
if not route then
error("Failed to create route")
end
local success, err = pcall(function()
local result = registerRoutes(route)
if not result then
error("Failed to register route: " .. r.route)
end
end)
if not success then
error("Error registering route: " .. err)
end
end
```
>[!NOTE]
> Register_routes and registerRoutes will show up as undefined as they are created at runtime when the server starts.
## Planned features
- Support for custom endpoint logic with the lua configuration :trollface: