|
2 | 2 | * @Author: Vincent Yang |
3 | 3 | * @Date: 2024-04-09 03:35:57 |
4 | 4 | * @LastEditors: Vincent Yang |
5 | | - * @LastEditTime: 2024-04-09 20:28:44 |
| 5 | + * @LastEditTime: 2025-07-12 04:55:18 |
6 | 6 | * @FilePath: /discord-image/main.go |
7 | 7 | * @Telegram: https://t.me/missuo |
8 | 8 | * @GitHub: https://github.com/missuo |
@@ -81,7 +81,6 @@ func main() { |
81 | 81 | r := gin.Default() |
82 | 82 | r.Use(cors.Default()) |
83 | 83 |
|
84 | | - // API routes must be defined before static file serving |
85 | 84 | // Upload image API |
86 | 85 | r.POST("/upload", func(c *gin.Context) { |
87 | 86 | host := c.Request.Host |
@@ -151,11 +150,21 @@ func main() { |
151 | 150 | c.Redirect(http.StatusFound, url) |
152 | 151 | }) |
153 | 152 |
|
154 | | - // Serve static files from public directory (Next.js export) |
155 | | - // This must come after all API routes to avoid conflicts |
156 | | - r.Static("/", "./public") |
157 | | - |
158 | | - // Fallback for SPA routing - serve index.html for any route that doesn't match static files or API routes |
| 153 | + // Serve Next.js static assets |
| 154 | + r.Static("/_next", "./public/_next") |
| 155 | + r.StaticFile("/favicon.ico", "./public/favicon.ico") |
| 156 | + r.StaticFile("/next.svg", "./public/next.svg") |
| 157 | + r.StaticFile("/vercel.svg", "./public/vercel.svg") |
| 158 | + r.StaticFile("/file.svg", "./public/file.svg") |
| 159 | + r.StaticFile("/globe.svg", "./public/globe.svg") |
| 160 | + r.StaticFile("/window.svg", "./public/window.svg") |
| 161 | + |
| 162 | + // Serve main page and handle SPA routing |
| 163 | + r.GET("/", func(c *gin.Context) { |
| 164 | + c.File("./public/index.html") |
| 165 | + }) |
| 166 | + |
| 167 | + // Fallback for SPA routing - serve index.html for any unmatched routes |
159 | 168 | r.NoRoute(func(c *gin.Context) { |
160 | 169 | c.File("./public/index.html") |
161 | 170 | }) |
|
0 commit comments