github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/http/service-serve-www.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package http 4 5 import ( 6 "../mediatype" 7 "../protocol" 8 "../service" 9 "../www" 10 ) 11 12 var ServeWWWService = serveWWWService{ 13 Service: service.New("", mediatype.New("domain/http.protocol.service; name=serve-www").SetDetail(protocol.LanguageEnglish, domainEnglish, 14 "Serve WWW", 15 "", 16 "", 17 "", 18 nil).SetInfo(protocol.Software_PreAlpha, 1587282740, "")). 19 SetAuthorization(protocol.CRUDAll, protocol.UserType_All), 20 } 21 22 type serveWWWService struct { 23 *service.Service 24 WWW www.Assets 25 } 26 27 // ServeWWW will serve WWW assets to request 28 func (ser *serveWWWService) ServeHTTP(stream protocol.Stream, httpReq *Request, httpRes *Response) (err protocol.Error) { 29 var reqFile, _ = ser.WWW.GUI.FileByPath(httpReq.uri.path) 30 if reqFile == nil { 31 // TODO::: SSR to serve-to-robots 32 // TODO::: Have default error pages and can get customizes! 33 // Send beauty HTML response in http error situation like 500, 404, ... 34 35 const supportedLang = "en" // TODO::: get from header 36 reqFile, err = ser.WWW.MainHTMLDir.File(supportedLang) 37 // if err != nil { 38 // TODO::: check other user language and at the end send better error 39 // } 40 } 41 httpRes.SetStatus(StatusOKCode, StatusOKPhrase) 42 httpRes.H.Set(HeaderKeyCacheControl, "max-age=31536000, immutable") 43 httpRes.SetBody(reqFile.Data()) 44 return 45 }