diff --git a/.gitignore b/.gitignore index 84159ec..87af672 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ go.work images/ main +node_modules +dist +bun.lockb \ No newline at end of file diff --git a/main.html b/index.html similarity index 88% rename from main.html rename to index.html index abd0840..66ffe97 100644 --- a/main.html +++ b/index.html @@ -2,7 +2,8 @@ CatGirls Town - + + @@ -34,7 +35,7 @@
- +
diff --git a/main.go b/main.go index da5a027..1fc385e 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "math/rand" "net/http" "os" + "strings" "text/template" ) @@ -30,6 +31,11 @@ func GetRandImg() string { return picsArray[rand.Intn(len(picsArray))] } +func ReturnPicFilename(w http.ResponseWriter, req *http.Request) { + var picFilename io.Reader = strings.NewReader(GetRandImg()) + io.Copy(w, picFilename) +} + func ReturnPic(w http.ResponseWriter, req *http.Request) { picture, _ := os.Open(fmt.Sprintf("images/%v", GetRandImg())) var pictureReader io.Reader = picture @@ -38,7 +44,7 @@ func ReturnPic(w http.ResponseWriter, req *http.Request) { } func ReturnHTML(w http.ResponseWriter, req *http.Request) { - htmlOpen, err := template.ParseFiles("main.html") + htmlOpen, err := template.ParseFiles("dist/index.html") if err != nil { log.Println(err.Error()) return @@ -51,9 +57,11 @@ func ReturnHTML(w http.ResponseWriter, req *http.Request) { func main() { log.Println("Server Start") imagesDir := http.FileServer(http.Dir("images")) - staticDir := http.FileServer(http.Dir("static")) + staticDir := http.FileServer(http.Dir("dist/assets")) http.Handle("/images/", http.StripPrefix("/images/", imagesDir)) - http.Handle("/static/", http.StripPrefix("/static/", staticDir)) + http.Handle("/assets/", http.StripPrefix("/assets/", staticDir)) + + http.HandleFunc("/rand", ReturnPicFilename) http.HandleFunc("/", ReturnHTML) http.ListenAndServe(":3666", nil) } diff --git a/package.json b/package.json new file mode 100644 index 0000000..471491f --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "picRan", + "private": "true", + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "preview": "vite preview" + }, + "devDependencies": { + "vite": "^6.0.1", + "axios": "1.7.9" + } +} \ No newline at end of file diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..192b5da --- /dev/null +++ b/src/main.js @@ -0,0 +1,7 @@ +import axios from "axios"; + +let pictureId = document.getElementById("CatGirlPicture") +pictureId.onclick = function() { + let picFilename = axios.get(location.href + "rand") + console.log(picFilename) +} diff --git a/static/picnic.min.css b/src/picnic.min.css similarity index 100% rename from static/picnic.min.css rename to src/picnic.min.css