Disclaimers
README is generated from Claude Sonnet AI, and reviewed by me. Please note that this project is for blog purposes only.
A comprehensive demonstration project showcasing Cross-Origin Resource Sharing (CORS) concepts using a modern full-stack application. This project features a Spring Boot backend API and a SvelteKit frontend, designed to help developers understand how CORS works in real-world applications.
This project implements Spring Boot & Svelte and demo with story of tracking system called "ใทใฃใ ใใณ (SHAMU Cat) Delivery" to demonstrate CORS configuration and behavior. The application consists of:
demystify-cors/
โ # Backend API (Port 8080)
โโโ spring-boot/
โ โโโ src/main/java/
โ โ โโโ blog/natta/santa/cors/
โ โ โโโ CorsApplication.java
โ โ โโโ config/
โ โ โ โ # CORS configuration
โ โ โ โโโ CorsConfig.java
โ โ โโโ delivery/
โ โ โโโ endpoint/
โ โ โ โโโ DeliveryController.java
โ โ โโโ response/
โ โ โโโ TrackingResultResponse.java
โ โโโ pom.xml
โ # Frontend (Port 5173)
โโโ svelte/
โ โโโ src/
โ โ โโโ routes/
โ โ โ โโโ +page.svelte
โ โ โโโ lib/
โ โโโ package.json
โ # API testing collection
โโโ bruno/
โโโ cors-demystify/
โโโ Tracking-Status.bru
Clone the repository
git clone [email protected]:santa-sandbox/demystify-cors.git
cd demystify-cors
Backend Setup (Spring Boot)
cd spring-boot
# Run in development mode
./mvnw spring-boot:run
# Or build and run
./mvnw clean package
java -jar target/cors-0.0.1-SNAPSHOT.jar
Frontend Setup (SvelteKit)
cd svelte
# Install dependencies
pnpm install
# Run development server
pnpm dev
Access the application
cd spring-boot
# Build for production
./mvnw clean package
# Build native binary (GraalVM required)
./mvnw clean package -Pnative
# Run native binary
./target/cors
Backend runs on: http://localhost:8080
cd svelte
# Build for production
pnpm build
# Preview production build
pnpm preview
Frontend runs on: http://localhost:5173
Frontend runs on: http://localhost:4173
/api/delivery/status/{trackingId}
GET http://localhost:8080/api/delivery/status/SHAMU001
{
"id": "SHAMU001",
"status": "processing",
"title": "Parcel is being processed",
"location": "Aichi",
"timestamp": "2025-06-19 18:00:00",
"estimatedDelivery": "2025-06-25 19:00:00"
}
The project demonstrates CORS configuration in the Spring Boot backend:
@Configuration
public class CorsConfig {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(@NonNull CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOrigins("http://localhost:5173");
}
};
}
}
bruno/cors-demystify/
Tracking-Status
request to test the APIBackend:
Frontend:
The Spring Boot application supports GraalVM native compilation:
cd spring-boot
# Build native image (requires GraalVM)
./mvnw clean package -Pnative
# Run native binary
./target/cors
This project helps you understand:
This project is open source and available under the MIT License.
Built with โค๏ธ to demystify CORS for developers worldwide ๐