package main
import (
"awesomeProject/Router"
"embed"
"net/http"
)
//go:embed frontend
var Content embed.FS
func main() {
// Serve static files under the "/static" path
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(Content))))
// Create a new handler using the router
mux := Router.NewHandler()
// Listen and serve on port 8081
http.ListenAndServe(":8081", mux)
}
import (
"awesomeProject/Router"
"embed"
"net/http"
)
//go:embed frontend
var Content embed.FS
func main() {
// Serve static files under the "/static" path
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(Content))))
// Create a new handler using the router
mux := Router.NewHandler()
// Listen and serve on port 8081
http.ListenAndServe(":8081", mux)
}
<!-- index.html -->
<!DOCTYPE html>
<html lang="ko">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="/static/css/home.css">
<head>
<meta charset="UTF-8">
<title>환영</title>
</head>
<body>
<section class="rain">
</section>
<section class="img">
<img src="/static/img/표지.png" alt="표지사진">
<p class="blink">Touch to Start</p>
<audio id="audio" autoplay loop>
<source src="https://ccrma.stanford.edu/~jos/mp3/harpsi-cs.mp3" type="audio/mp3">
</audio>
</section>
</body>
<script src="/static/js/rain.js"></script>
</html>
<!DOCTYPE html>
<html lang="ko">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="/static/css/home.css">
<head>
<meta charset="UTF-8">
<title>환영</title>
</head>
<body>
<section class="rain">
</section>
<section class="img">
<img src="/static/img/표지.png" alt="표지사진">
<p class="blink">Touch to Start</p>
<audio id="audio" autoplay loop>
<source src="https://ccrma.stanford.edu/~jos/mp3/harpsi-cs.mp3" type="audio/mp3">
</audio>
</section>
</body>
<script src="/static/js/rain.js"></script>
</html>
프론트 파일 구조는 - awesomeProject
- frontend
- css
- home.css
- img
- 표지.png
- js
- rain.js
- index.html
이렇습니다
몇시간쨰 찾아보면서 해도 안되네요 왜이러는 걸까요 ㅜ
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./frontend")))) 이런 식으로 해도 안되나요?
테스트 해봤는데, http.FS 말고 http.Dir 사용하니까 적용되네요.