Skip to content
Snippets Groups Projects
Commit d4717ae0 authored by Byron Biggs's avatar Byron Biggs
Browse files

Merge remote-tracking branch 'origin/main'

parents 27a412e0 ddb04f7a
Branches
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ public class SurveyController { ...@@ -27,6 +27,7 @@ public class SurveyController {
return "results"; // Returns the Thymeleaf results page return "results"; // Returns the Thymeleaf results page
} }
@CrossOrigin(origins = "http://localhost:3000") // Or your frontend URL
@PostMapping("/api/survey/submit") @PostMapping("/api/survey/submit")
@ResponseBody @ResponseBody
public ResponseEntity<String> submitSurvey(@RequestBody SurveyData surveyData) { public ResponseEntity<String> submitSurvey(@RequestBody SurveyData surveyData) {
...@@ -43,6 +44,7 @@ public class SurveyController { ...@@ -43,6 +44,7 @@ public class SurveyController {
} }
// New endpoint to fetch survey results // New endpoint to fetch survey results
@CrossOrigin(origins = "http://localhost:3000") // Allow cross-origin requests
@GetMapping("/api/survey/results") @GetMapping("/api/survey/results")
@ResponseBody @ResponseBody
public ResponseEntity<List<SurveyResultDTO>> getSurveyResults() { public ResponseEntity<List<SurveyResultDTO>> getSurveyResults() {
......
package com.example.demo.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOrigins("*") // Allow any origin - replace with specific origins in production
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.maxAge(3600); // 1 hour cache for CORS preflight requests
}
}
\ No newline at end of file
...@@ -251,9 +251,9 @@ function submitSurvey() { ...@@ -251,9 +251,9 @@ function submitSurvey() {
console.log('Survey Submitted:', surveyResponses); // Debugging Log (Replace with database sender) console.log('Survey Submitted:', surveyResponses); // Debugging Log (Replace with database sender)
// Send the AJAX request with dynamic URL // Send the AJAX request
$.ajax({ $.ajax({
url: window.location.origin + "/api/survey/submit", url: "http://localhost:8080/api/survey/submit",
type: "POST", type: "POST",
contentType: "application/json", // Ensures the content type is set to JSON contentType: "application/json", // Ensures the content type is set to JSON
data: JSON.stringify({responses: surveyResponses}), // Convert the data into a JSON string data: JSON.stringify({responses: surveyResponses}), // Convert the data into a JSON string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment