Compare commits
No commits in common. "7ee67d3f2d77d7f18238a3b3e3eaaccd1a887876" and "a9caca277234797fe02c4a490d26f34a825f13ee" have entirely different histories.
7ee67d3f2d
...
a9caca2772
20
Dockerfile
20
Dockerfile
@ -1,5 +1,5 @@
|
|||||||
FROM golang:1.23-alpine3.20 AS go-builder
|
FROM golang:1.23-alpine3.20 as go-builder
|
||||||
ENV GOPATH=""
|
ENV GOPATH ""
|
||||||
|
|
||||||
RUN apk add git
|
RUN apk add git
|
||||||
|
|
||||||
@ -9,24 +9,8 @@ RUN go mod download
|
|||||||
ADD ./ .
|
ADD ./ .
|
||||||
RUN go build -o ./server .
|
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
|
FROM alpine:3.14
|
||||||
|
|
||||||
COPY --from=go-builder /app/server /app/server
|
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"]
|
ENTRYPOINT ["/app/server"]
|
||||||
|
4
Makefile
4
Makefile
@ -1,4 +0,0 @@
|
|||||||
.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"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed static/robots.txt
|
//go:embed static/index.html
|
||||||
var robotsTxt []byte
|
var indexPage string
|
||||||
|
|
||||||
type Params struct {
|
type Params struct {
|
||||||
MatrixHostname string
|
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/server", http.HandlerFunc(h.getMatrixServer))
|
||||||
h.Handle("GET /.well-known/matrix/client", http.HandlerFunc(h.getMatrixClient))
|
h.Handle("GET /.well-known/matrix/client", http.HandlerFunc(h.getMatrixClient))
|
||||||
h.Handle("GET /robots.txt", http.HandlerFunc(h.getRobotsTxt))
|
h.Handle("GET /{$}", http.HandlerFunc(h.getHomepage))
|
||||||
h.Handle("GET /", http.FileServer(http.Dir(params.RootPath)))
|
h.Handle("GET /", http.FileServer(http.Dir(params.RootPath)))
|
||||||
|
|
||||||
return h
|
return h
|
||||||
@ -45,8 +45,10 @@ func (h *handler) getMatrixClient(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write([]byte(`{"m.homeserver": {"base_url": "` + h.params.MatrixBaseURL + `"}}`))
|
w.Write([]byte(`{"m.homeserver": {"base_url": "` + h.params.MatrixBaseURL + `"}}`))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handler) getRobotsTxt(w http.ResponseWriter, r *http.Request) {
|
func (h *handler) getHomepage(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add("content-type", "text/plain")
|
w.Header().Add("content-type", "text/html")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write(robotsTxt)
|
if r.Method == http.MethodGet {
|
||||||
|
w.Write([]byte(indexPage))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,14 +41,6 @@ func TestHandler(t *testing.T) {
|
|||||||
wantStatusCode: http.StatusOK,
|
wantStatusCode: http.StatusOK,
|
||||||
wantBody: `{"m.homeserver": {"base_url": "https://foo.example.com"}}`,
|
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",
|
name: "GET /test.html",
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
@ -61,15 +53,15 @@ func TestHandler(t *testing.T) {
|
|||||||
name: "GET /",
|
name: "GET /",
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
path: "/",
|
path: "/",
|
||||||
wantContentType: "text/html; charset=utf-8",
|
wantContentType: "text/html",
|
||||||
wantStatusCode: http.StatusOK,
|
wantStatusCode: http.StatusOK,
|
||||||
wantBody: "<html>\n <head>\n <title>Homepage</title>\n </head>\n</html>\n",
|
wantBody: "Welcome to netflux.io",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "HEAD /",
|
name: "HEAD /",
|
||||||
method: http.MethodHead,
|
method: http.MethodHead,
|
||||||
path: "/",
|
path: "/",
|
||||||
wantContentType: "text/html; charset=utf-8",
|
wantContentType: "text/html",
|
||||||
wantStatusCode: http.StatusOK,
|
wantStatusCode: http.StatusOK,
|
||||||
wantBody: "",
|
wantBody: "",
|
||||||
},
|
},
|
||||||
@ -113,7 +105,6 @@ func TestHandler(t *testing.T) {
|
|||||||
|
|
||||||
respBody, err := io.ReadAll(resp.Body)
|
respBody, err := io.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Contains(t, string(respBody), tc.wantBody)
|
assert.Contains(t, string(respBody), tc.wantBody)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
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: /
|
|
5
handler/testdata/static/index.html
vendored
5
handler/testdata/static/index.html
vendored
@ -1,5 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Homepage</title>
|
|
||||||
</head>
|
|
||||||
</html>
|
|
Loading…
x
Reference in New Issue
Block a user