Skip to content
Snippets Groups Projects
Commit caef048c authored by Birk Øvstetun Narvhus's avatar Birk Øvstetun Narvhus
Browse files

Merge branch 'Cors' into 'main'

Cors + folder structure

See merge request idatt2106-v23-03/backend!2
parents ab3af8f9 12a91236
No related branches found
No related tags found
No related merge requests found
Showing
with 124 additions and 3 deletions
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
......@@ -2,17 +2,20 @@
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="SmartMat" />
<module name="backend" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="SmartMat" options="-parameters" />
<module name="backend" options="-parameters" />
</option>
</component>
</project>
\ No newline at end of file
......@@ -8,5 +8,5 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
package ntnu.idatt2016.v233.SmartMat;
import ntnu.idatt2016.v233.SmartMat.config.properties.DomainProperty;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties({DomainProperty.class})
public class SmartMatApplication {
public static void main(String[] args) {
......
package ntnu.idatt2016.v233.SmartMat.config;
import lombok.AllArgsConstructor;
import ntnu.idatt2016.v233.SmartMat.config.properties.DomainProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.Arrays;
/**
* Cors configuration for application
* @author Birk
* @version 1.0
*
*/
@Configuration
@AllArgsConstructor
public class CorsConfig {
/**
* The frontend domain properties.
*/
private final DomainProperty domainProperty;
/**
* Configures CORS for the application.
* @return {@link WebMvcConfigurer} with CORS configuration
*/
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(domainProperty.domain())
.allowedMethods(Arrays.asList(
HttpMethod.GET.name(),
HttpMethod.POST.name(),
HttpMethod.PUT.name(),
HttpMethod.DELETE.name(),
HttpMethod.OPTIONS.name()
).toArray(String[]::new))
.allowedHeaders("*")
.allowCredentials(true)
.maxAge(3600);
}
};
}
}
package ntnu.idatt2016.v233.SmartMat.config;
public class SecurityConfig {
}
package ntnu.idatt2016.v233.SmartMat.config.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "domain")
public record DomainProperty (String domain){
}
package ntnu.idatt2016.v233.SmartMat.controller;
public class UserController {
}
package ntnu.idatt2016.v233.SmartMat.entity;
public class User {
}
package ntnu.idatt2016.v233.SmartMat.repository;
public class temp {
}
package ntnu.idatt2016.v233.SmartMat.service;
public class tempService {
}
package ntnu.idatt2016.v233.SmartMat.util;
public class tempUtil {
}
domain.domain = "localhost:5334";
\ No newline at end of file
domain.domain = "localhost:5334";
\ No newline at end of file
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment