kserver

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2024 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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-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:

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:


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:

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址