fix: resolve JSON.parse error in frontend API calls
- Add error handling for JSON encoding in all backend handlers - Add CORS support to backend server - Add proxy configuration for frontend development server - Improve error handling in frontend API calls - Build frontend to create static files for backend serving - Add comprehensive error messages and user feedback Fixes issue where frontend received malformed JSON responses from backend API.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"markdown-editor/internal/logger"
|
||||
"markdown-editor/internal/storage"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/rs/cors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -73,6 +74,15 @@ func (s *Server) setupRoutes() {
|
||||
frontendDir = frontendDirEnv
|
||||
}
|
||||
s.router.PathPrefix("/").Handler(http.FileServer(http.Dir(frontendDir)))
|
||||
|
||||
// Enable CORS
|
||||
cors := cors.New(cors.Options{
|
||||
AllowedOrigins: []string{"http://localhost:3000", "http://localhost:8080"},
|
||||
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
||||
AllowedHeaders: []string{"Content-Type", "Authorization"},
|
||||
AllowCredentials: true,
|
||||
})
|
||||
s.router.Use(cors.Handler)
|
||||
}
|
||||
|
||||
func (s *Server) serve() error {
|
||||
|
||||
Reference in New Issue
Block a user