aboutsummaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-04-06 03:00:22 +0700
committerShulhan <m.shulhan@gmail.com>2020-04-06 03:00:22 +0700
commitdb5b35cd5052d47c81bb63f78f7781513be22fd2 (patch)
treec393a2aa937a0b576a9f25c10b76dd8967a90b02 /server.go
parent5ea27bffa9020ddcdc62774a29e399e76ae5997c (diff)
downloadkamusku-db5b35cd5052d47c81bb63f78f7781513be22fd2.tar.xz
www-kbbi: add content page for "/project/kbbi"
The content page show the definition and capabilities of the API.
Diffstat (limited to 'server.go')
-rw-r--r--server.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/server.go b/server.go
index e0e6b9c..7969ca2 100644
--- a/server.go
+++ b/server.go
@@ -12,6 +12,7 @@ import (
"sync"
"time"
+ "github.com/shuLhan/share/lib/debug"
"github.com/shuLhan/share/lib/http"
)
@@ -44,9 +45,14 @@ type Server struct {
//
func NewServer(kamusStorage string) (server *Server, err error) {
opts := &http.ServerOptions{
+ Root: "_content",
Address: defListen,
}
+ if debug.Value > 0 {
+ opts.Development = true
+ }
+
server = &Server{
stopped: make(chan bool, 1),
}
@@ -78,7 +84,7 @@ func NewServer(kamusStorage string) (server *Server, err error) {
// Start the HTTP server.
//
func (server *Server) Start() (err error) {
- go server.dumpCache()
+ go server.dumpCacheJob()
server.wg.Add(1)
return server.http.Start()
@@ -88,7 +94,7 @@ func (server *Server) Start() (err error) {
// Shutdown the HTTP server and save the cache for future use.
//
func (server *Server) Shutdown() (err error) {
- err = server.Shutdown()
+ err = server.http.Shutdown(nil)
server.stopped <- true
@@ -134,6 +140,8 @@ func (server *Server) handleDefinisi(
httpReq *stdhttp.Request,
reqBody []byte,
) (resBody []byte, err error) {
+ httpRes.Header().Set(headerNameACAO, "*")
+
paramKata := httpReq.Form.Get(paramNameKata)
if len(paramKata) == 0 {
return []byte(emptyResponse), nil