Compare commits

..

3 Commits

Author SHA1 Message Date
httpjamesm 72a7392142 Merge branch 'main' into concurrency-improvements 2023-08-21 01:08:06 -04:00
httpjamesm 1f77bf4ed6 Merge branch 'main' into concurrency-improvements 2023-08-21 01:07:02 -04:00
httpjamesm 50fc162b47 refactor: concurrently proxy img tags 2023-08-21 01:04:11 -04:00
9 changed files with 22 additions and 90 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
docker-compose.yml
.DS_Store
*bin
/tmp
/tmp
-6
View File
@@ -1,6 +0,0 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
+9 -14
View File
@@ -1,24 +1,19 @@
FROM golang:1.19-alpine as build
FROM golang:1.18-alpine
RUN apk add musl-dev
RUN apk add libc-dev
RUN apk add gcc
WORKDIR /app
COPY go.mod .
COPY go.sum .
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY . .
COPY ./ /app
ENV CGO_ENABLED=0
RUN go build -o anonymousoverflow
FROM scratch
COPY --from=build /app/anonymousoverflow /anonymousoverflow
COPY templates /templates
COPY public /public
COPY --from=build /etc/ssl/certs /etc/ssl/certs
RUN go build -o /anonymousoverflow
EXPOSE 8080
+1 -1
View File
@@ -1,3 +1,3 @@
package config
var Version = "1.9.0"
var Version = "1.8.3"
-2
View File
@@ -50,8 +50,6 @@ func main() {
r.GET("/", routes.GetHome)
r.POST("/", routes.PostHome)
r.GET("/a/:id", routes.RedirectShortenedOverflowURL)
r.GET("/questions/:id", func(c *gin.Context) {
// redirect user to the question with the title
c.Redirect(302, fmt.Sprintf("/questions/%s/placeholder", c.Param("id")))
+4 -3
View File
@@ -10,7 +10,7 @@
--link-color: #92adff;
}
[data-theme='light'] {
[data-theme="light"] {
--main-bg: rgb(219, 219, 219);
--text-color: #000;
--muted-text-color: #636363;
@@ -26,6 +26,7 @@ a {
color: var(--link-color);
}
html {
margin: 0;
padding: 0;
@@ -44,9 +45,9 @@ html {
.icon img {
background: white;
border-radius: 50%;
padding: 0.25rem;
padding: .25rem;
}
details {
cursor: pointer;
}
}
+5 -13
View File
@@ -19,17 +19,9 @@ body {
box-sizing: border-box;
}
@media (orientation: landscape) {
.parent {
max-width: 50%;
width: fit-content;
}
}
@media (orientation: portrait) {
.parent {
max-width: 90%;
width: fit-content;
}
.parent {
max-width: 90%;
width: fit-content;
}
.header {
@@ -39,7 +31,7 @@ body {
.card-tags {
display: flex;
gap: 0.5rem;
gap: .5rem;
}
.card-tags .tag {
@@ -102,7 +94,7 @@ img {
margin-bottom: 1rem;
background-color: var(--meta-bg);
color: var(--text-color);
display: flex;
justify-content: space-between;
align-items: center;
+2 -6
View File
@@ -35,14 +35,10 @@ func PostHome(c *gin.Context) {
soLink := body.URL
// remove the www.
soLink = strings.ReplaceAll(soLink, "www.", "")
// validate URL
isStackOverflow := strings.HasPrefix(soLink, "https://stackoverflow.com/questions/")
isShortenedStackOverflow := strings.HasPrefix(soLink, "https://stackoverflow.com/a/")
isStackExchange := stackExchangeRegex.MatchString(soLink)
if !isStackExchange && !isStackOverflow && !isShortenedStackOverflow {
if !isStackExchange && !isStackOverflow {
c.HTML(400, "home.html", gin.H{
"errorMessage": "Invalid stack overflow/exchange URL",
"theme": c.MustGet("theme").(string),
@@ -51,7 +47,7 @@ func PostHome(c *gin.Context) {
}
// if stack overflow, trim https://stackoverflow.com
if isStackOverflow || isShortenedStackOverflow {
if isStackOverflow {
c.Redirect(302, strings.TrimPrefix(soLink, "https://stackoverflow.com"))
return
}
-44
View File
@@ -1,44 +0,0 @@
package routes
import (
"fmt"
"net/http"
"os"
"github.com/gin-gonic/gin"
"github.com/go-resty/resty/v2"
)
func RedirectShortenedOverflowURL(c *gin.Context) {
id := c.Param("id")
// fetch the stack overflow URL
client := resty.New()
client.SetRedirectPolicy(
resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}),
)
resp, err := client.R().Get(fmt.Sprintf("https://www.stackoverflow.com/a/%s", id))
if err != nil {
c.HTML(400, "home.html", gin.H{
"errorMessage": "Unable to fetch stack overflow URL",
"theme": c.MustGet("theme").(string),
})
return
}
if resp.StatusCode() != 302 {
c.HTML(400, "home.html", gin.H{
"errorMessage": fmt.Sprintf("Unexpected HTTP status from origin: %d", resp.StatusCode()),
"theme": c.MustGet("theme").(string),
})
return
}
// get the redirect URL
location := resp.Header().Get("Location")
c.Redirect(302, fmt.Sprintf("%s%s", os.Getenv("APP_URL"), location))
}