Skip to content

Commit

Permalink
Merge pull request #69 from fabiante/feat/landing-page
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiante authored Sep 20, 2023
2 parents 2b3fac0 + 02c12f2 commit 9d7939a
Show file tree
Hide file tree
Showing 20 changed files with 1,816 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ jobs:
- name: Build
run: go build -v ./...

build-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build image
run: docker build --target runtime .

test-load:
runs-on: ubuntu-latest
env:
Expand Down
23 changes: 22 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
# Build the application from source
# This layer builds the webapp
FROM node as build-webapp

WORKDIR /app

COPY webapp/package.json webapp/package-lock.json ./

WORKDIR webapp

RUN npm ci

COPY webapp/ ./

RUN npm run build

# This layer builds the go application
FROM golang:latest AS build

WORKDIR /app

# Copy go module files to download dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy prebuild webapp
COPY --from=build-webapp /app/webapp/dist ./webapp/dist

# Copy go source code
COPY . ./

# Build go application
RUN CGO_ENABLED=0 go build -o /persurl cli/main.go

FROM alpine AS runtime
Expand Down
3 changes: 3 additions & 0 deletions api/server_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"

"github.com/DEXPRO-Solutions-GmbH/swaggerui"
"github.com/fabiante/persurl/webapp"
"github.com/gin-gonic/gin"
)

Expand All @@ -18,6 +19,8 @@ func SetupRouting(r gin.IRouter, s *Server) {
swaggerUI.Register(r)
}

webapp.Register(r)

validDomain := validPathVar("domain", regexNamed)
validName := validPathVar("name", regexNamed)

Expand Down
25 changes: 25 additions & 0 deletions webapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist/*
!dist/.gitkeep
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions webapp/dist/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This keeps the dist dir in version control.
This is required because embed.go is build during tests and would fail if
the dist directory would not exist.
25 changes: 25 additions & 0 deletions webapp/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package webapp

import (
"embed"
"io/fs"
"net/http"

"github.com/gin-gonic/gin"
)

//go:embed dist/*
var dist embed.FS

func Register(r gin.IRoutes) {
r.GET("/", func(ctx *gin.Context) {
ctx.Redirect(http.StatusPermanentRedirect, "/webapp")
})

subFs, err := fs.Sub(dist, "dist")
if err != nil {
panic(err)
}

r.StaticFS("/webapp", http.FS(subFs))
}
15 changes: 15 additions & 0 deletions webapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<!-- TODO: Add custom icon once persurl has an icon -->
<!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" />-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="light dark" />
<title>PersURL</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
Loading

0 comments on commit 9d7939a

Please sign in to comment.