Skip to content

Commit

Permalink
Read sitemap and robots from res instead of the local dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaraa committed Feb 24, 2024
1 parent 3ebd5e4 commit a1c1ecd
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io"
"net/http"
"os"
"strings"
"time"

Expand Down Expand Up @@ -55,15 +54,15 @@ func handelErrorPage(w http.ResponseWriter, r *http.Request) {

func handleHomePage(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.URL.Path, "robots.txt") {
robotsFile, _ := os.ReadFile("./resources/robots.txt")
robotsFile, _ := res.ReadFile("resources/robots.txt")
w.Header().Set("Content-Type", "text/plain")
_, _ = w.Write(robotsFile)
return
}
if strings.Contains(r.URL.Path, "sitemap.xml") {
robotsFile, _ := os.ReadFile("./resources/sitemap.xml")
sitemapFile, _ := res.ReadFile("resources/sitemap.xml")
w.Header().Set("Content-Type", "text/plain")
_, _ = w.Write(robotsFile)
_, _ = w.Write(sitemapFile)
return
}

Expand Down

0 comments on commit a1c1ecd

Please sign in to comment.