Skip to content

Generate a simple website with static pages and easily add APIs to your server with gofiber.

License

Notifications You must be signed in to change notification settings

tkdeng/simplewebserver

Repository files navigation

Simple Web Server

Compile HTML and MD template files together into a static html website.

This module uses gofiber and staticweb to create a quick and easy setup for a simple web server.

For extra performance, consider adding the pages.dist directory to a cdn (like cloudflare pages) to serve static html pages.

Installation

# install the go module
go get github.com/tkdeng/simplewebserver

# install dependencies
make

Dependencies

Debian/Ubuntu (Linux)

  sudo apt install libpcre3-dev

Fedora (Linux)

  sudo dnf install pcre-devel

Arch (Linux)

  sudo yum install pcre-dev

Usage

import (
  server "github.com/tkdeng/simplewebserver"
)

func main(){
  // create new server
  app, err := server.New("./app")

  //note: page.dist files will automatically be statically rendered,
  // and take priority over gofiber methods

  // do normal gofiber stuff (optional)
  app.Get("/api", func(c fiber.Ctx) error {
    return c.SendString("Hello, API!")
  })

  //note: page.dist files will automatically be statically rendered,
  // and take priority over gofiber methods
  app.Get("/", func(c fiber.Ctx) error {
    // this will be ignored if index.html exists
    return c.SendString("Hello, World!")
  })

  // listen with openssl (default port: [http: 8080, ssl: 8443])
  err = app.Listen()
}

Inside App Directory

config.yml

title: "Web Server"
app_title: "WebServer"
desc: "A Web Server."

public_uri: "/public/"

port_http: 8080
port_ssl: 8443

origins: [
  "localhost",
  "example.com",
]

proxies: [
  "127.0.0.1",
  "192.168.0.1",
]

DebugMode: no

About

Generate a simple website with static pages and easily add APIs to your server with gofiber.

Resources

License

Stars

Watchers

Forks

Packages

No packages published