aboutsummaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-02-11 22:50:27 +0700
committerShulhan <ms@kilabit.info>2026-02-11 22:50:53 +0700
commit00dfc937cec1b7eb9ebb1024fae5228ebf9f0341 (patch)
treeb0aaca000ad59993a0a862dda17a7fd778cf1518 /server.go
parent1e833ea2a7d0300915c4c8a5c7bef09909ada915 (diff)
downloadciigo-00dfc937cec1b7eb9ebb1024fae5228ebf9f0341.tar.xz
cmd/ciigo: add option to set base path and shutdown idle duration
The `-base-path` option set the URL prefix for serving HTTP request. This allow serving the content under the prefix other than "/". The `-shutdown-idle` option set the duration when server will stop accepting new connections and shutting down. This option can be helpful to reduce the resources on local environment.
Diffstat (limited to 'server.go')
-rw-r--r--server.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/server.go b/server.go
index f8270b8..b17cb5f 100644
--- a/server.go
+++ b/server.go
@@ -195,17 +195,17 @@ func (ciigo *Ciigo) onGet(
) (out *memfs.Node, statusCode int) {
var (
logp = `onGet`
- file string
+ file = req.URL.Path
)
if node == nil {
// File does not exist.
- file = req.URL.Path
- ext := path.Ext(file)
+ ext := path.Ext(req.URL.Path)
if ext == `.adoc` || ext == `.md` {
// Redirect to .html.
- file = strings.TrimSuffix(file, ext) + `.html`
- http.Redirect(w, req, file, http.StatusSeeOther)
+ req.URL.Path = strings.TrimSuffix(req.URL.Path, ext) + `.html`
+ req.URL.Path = path.Join(ciigo.serveOpts.BasePath, req.URL.Path)
+ http.Redirect(w, req, req.URL.String(), http.StatusSeeOther)
return nil, http.StatusSeeOther
}
} else if ciigo.serveOpts.IsDevelopment {