Compare commits
2 Commits
a9caca2772
...
7ee67d3f2d
Author | SHA1 | Date |
---|---|---|
Rob Watson | 7ee67d3f2d | |
Rob Watson | 881f37f89c |
20
Dockerfile
20
Dockerfile
|
@ -1,5 +1,5 @@
|
|||
FROM golang:1.23-alpine3.20 as go-builder
|
||||
ENV GOPATH ""
|
||||
FROM golang:1.23-alpine3.20 AS go-builder
|
||||
ENV GOPATH=""
|
||||
|
||||
RUN apk add git
|
||||
|
||||
|
@ -9,8 +9,24 @@ RUN go mod download
|
|||
ADD ./ .
|
||||
RUN go build -o ./server .
|
||||
|
||||
|
||||
FROM hugomods/hugo:latest AS blog-builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk update && \
|
||||
apk add git && \
|
||||
git clone https://git.netflux.io/rob/netflux-blog blog && \
|
||||
cd blog && \
|
||||
git submodule update --init --recursive && \
|
||||
hugo
|
||||
|
||||
|
||||
FROM alpine:3.14
|
||||
|
||||
COPY --from=go-builder /app/server /app/server
|
||||
COPY --from=blog-builder /app/blog/public /www/html
|
||||
|
||||
ENV NETFLUX_ROOT_PATH=/www/html
|
||||
|
||||
ENTRYPOINT ["/app/server"]
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
.PHONY: deploy
|
||||
deploy: # build and deploy the latest version of the image.
|
||||
docker build -t netfluxio/homepage:latest .
|
||||
docker push netfluxio/homepage:latest
|
|
@ -5,8 +5,8 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed static/index.html
|
||||
var indexPage string
|
||||
//go:embed static/robots.txt
|
||||
var robotsTxt []byte
|
||||
|
||||
type Params struct {
|
||||
MatrixHostname string
|
||||
|
@ -27,7 +27,7 @@ func New(params Params) http.Handler {
|
|||
|
||||
h.Handle("GET /.well-known/matrix/server", http.HandlerFunc(h.getMatrixServer))
|
||||
h.Handle("GET /.well-known/matrix/client", http.HandlerFunc(h.getMatrixClient))
|
||||
h.Handle("GET /{$}", http.HandlerFunc(h.getHomepage))
|
||||
h.Handle("GET /robots.txt", http.HandlerFunc(h.getRobotsTxt))
|
||||
h.Handle("GET /", http.FileServer(http.Dir(params.RootPath)))
|
||||
|
||||
return h
|
||||
|
@ -45,10 +45,8 @@ func (h *handler) getMatrixClient(w http.ResponseWriter, r *http.Request) {
|
|||
w.Write([]byte(`{"m.homeserver": {"base_url": "` + h.params.MatrixBaseURL + `"}}`))
|
||||
}
|
||||
|
||||
func (h *handler) getHomepage(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("content-type", "text/html")
|
||||
func (h *handler) getRobotsTxt(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("content-type", "text/plain")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if r.Method == http.MethodGet {
|
||||
w.Write([]byte(indexPage))
|
||||
}
|
||||
w.Write(robotsTxt)
|
||||
}
|
||||
|
|
|
@ -41,6 +41,14 @@ func TestHandler(t *testing.T) {
|
|||
wantStatusCode: http.StatusOK,
|
||||
wantBody: `{"m.homeserver": {"base_url": "https://foo.example.com"}}`,
|
||||
},
|
||||
{
|
||||
name: "GET /robots.txt",
|
||||
method: http.MethodGet,
|
||||
path: "/robots.txt",
|
||||
wantContentType: "text/plain",
|
||||
wantStatusCode: http.StatusOK,
|
||||
wantBody: "Allow: /",
|
||||
},
|
||||
{
|
||||
name: "GET /test.html",
|
||||
method: http.MethodGet,
|
||||
|
@ -53,15 +61,15 @@ func TestHandler(t *testing.T) {
|
|||
name: "GET /",
|
||||
method: http.MethodGet,
|
||||
path: "/",
|
||||
wantContentType: "text/html",
|
||||
wantContentType: "text/html; charset=utf-8",
|
||||
wantStatusCode: http.StatusOK,
|
||||
wantBody: "Welcome to netflux.io",
|
||||
wantBody: "<html>\n <head>\n <title>Homepage</title>\n </head>\n</html>\n",
|
||||
},
|
||||
{
|
||||
name: "HEAD /",
|
||||
method: http.MethodHead,
|
||||
path: "/",
|
||||
wantContentType: "text/html",
|
||||
wantContentType: "text/html; charset=utf-8",
|
||||
wantStatusCode: http.StatusOK,
|
||||
wantBody: "",
|
||||
},
|
||||
|
@ -105,6 +113,7 @@ func TestHandler(t *testing.T) {
|
|||
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Contains(t, string(respBody), tc.wantBody)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
User-agent: AI2Bot
|
||||
User-agent: Ai2Bot-Dolma
|
||||
User-agent: Amazonbot
|
||||
User-agent: anthropic-ai
|
||||
User-agent: Applebot
|
||||
User-agent: Applebot-Extended
|
||||
User-agent: Bytespider
|
||||
User-agent: CCBot
|
||||
User-agent: ChatGPT-User
|
||||
User-agent: Claude-Web
|
||||
User-agent: ClaudeBot
|
||||
User-agent: cohere-ai
|
||||
User-agent: Diffbot
|
||||
User-agent: DuckAssistBot
|
||||
User-agent: FacebookBot
|
||||
User-agent: FriendlyCrawler
|
||||
User-agent: Google-Extended
|
||||
User-agent: GoogleOther
|
||||
User-agent: GoogleOther-Image
|
||||
User-agent: GoogleOther-Video
|
||||
User-agent: GPTBot
|
||||
User-agent: iaskspider/2.0
|
||||
User-agent: ICC-Crawler
|
||||
User-agent: ImagesiftBot
|
||||
User-agent: img2dataset
|
||||
User-agent: ISSCyberRiskCrawler
|
||||
User-agent: Kangaroo Bot
|
||||
User-agent: Meta-ExternalAgent
|
||||
User-agent: Meta-ExternalFetcher
|
||||
User-agent: OAI-SearchBot
|
||||
User-agent: omgili
|
||||
User-agent: omgilibot
|
||||
User-agent: PerplexityBot
|
||||
User-agent: PetalBot
|
||||
User-agent: Scrapy
|
||||
User-agent: Sidetrade indexer bot
|
||||
User-agent: Timpibot
|
||||
User-agent: VelenPublicWebCrawler
|
||||
User-agent: Webzio-Extended
|
||||
User-agent: YouBot
|
||||
Disallow: /
|
||||
|
||||
User-agent: *
|
||||
Allow: /
|
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Homepage</title>
|
||||
</head>
|
||||
</html>
|
Loading…
Reference in New Issue