Browse Source

dealing with cors

David Thornley 6 years ago
parent
commit
c7dcfbbe10

+ 1
- 1
src/main/java/com/ziplinegreen/vault/Config/WebSocketConfig.java View File

@@ -21,6 +21,6 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
21 21
 
22 22
     @Override
23 23
     public void registerStompEndpoints(StompEndpointRegistry registry) {
24
-        registry.addEndpoint("/vault-socket").setAllowedOrigins("*").withSockJS();
24
+        registry.addEndpoint("/vault-socket").setAllowedOrigins("localhost:8100").withSockJS();
25 25
     }
26 26
 }

+ 1
- 1
src/main/java/com/ziplinegreen/vault/Controller/PostController.java View File

@@ -29,7 +29,7 @@ public class PostController {
29 29
         return postService.createPost(post);
30 30
     }
31 31
 
32
-    @CrossOrigin
32
+    @CrossOrigin(origins = "https://fast-headland-39537.herokuapp.com")
33 33
     @GetMapping("/posts/all")
34 34
     public Iterable<Post> getAllPosts() {
35 35
         return postService.getAllPosts();

+ 7
- 0
src/main/java/com/ziplinegreen/vault/Controller/UserController.java View File

@@ -23,9 +23,16 @@ public class UserController {
23 23
 
24 24
     @GetMapping("/users/{userId}")
25 25
     public User getUserById(@PathVariable Long userId) {
26
+
26 27
         return userService.findUserById(userId);
27 28
     }
29
+    @CrossOrigin
30
+    @GetMapping("/users/{username}")
31
+    public User getUserById(@PathVariable String username) {
28 32
 
33
+        return userService.findUserByUsername(username);
34
+    }
35
+    @CrossOrigin
29 36
     @PutMapping("/users/{userId}")
30 37
     public User updateUsername(@PathVariable Long userId, @RequestBody String username) {
31 38
         return userService.updateUsername(userId, username);

+ 5
- 0
src/main/java/com/ziplinegreen/vault/Repository/UsersRepository.java View File

@@ -2,6 +2,11 @@ package com.ziplinegreen.vault.Repository;
2 2
 
3 3
 import com.ziplinegreen.vault.Model.User;
4 4
 import org.springframework.data.jpa.repository.JpaRepository;
5
+import org.springframework.data.jpa.repository.Query;
6
+import org.springframework.data.repository.query.Param;
5 7
 
6 8
 public interface UsersRepository extends JpaRepository<User, Long> {
9
+
10
+    @Query(value = "SELECT u FROM User u WHERE u.username = :username")
11
+    User findUserByUsername(@Param("username") String username);
7 12
 }

+ 2
- 0
src/main/java/com/ziplinegreen/vault/Service/UserService.java View File

@@ -29,6 +29,8 @@ public class UserService {
29 29
         return userRepository.findById(id).get();
30 30
     }
31 31
 
32
+    public User findUserByUsername(String username) { return userRepository.findUserByUsername(username);}
33
+
32 34
     public User updateUsername(Long userId, String username){
33 35
         User user = findUserById(userId);
34 36
         user.setUsername(username);

+ 1
- 23
src/main/resources/application.properties View File

@@ -1,13 +1,4 @@
1
-## H2
2
-#spring.h2.console.enabled=true
3
-#spring.h2.console.path=/h2
4
-#
5
-## Datasource
6
-#spring.datasource.url=jdbc:h2:file:~/test
7
-#spring.datasource.username=sa
8
-#spring.datasource.password=
9
-#spring.datasource.driver-class-name=org.h2.Driver
10
-
1
+#PostGresql set up
11 2
 spring.datasource.url= jdbc:postgresql://localhost:5432/thevault 
12 3
 spring.datasource.username=postgres
13 4
 spring.datasource.password=ZipCode4dot1   
@@ -18,16 +9,3 @@ spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
18 9
 
19 10
 # Because detection is disabled you have to set correct dialect by hand.
20 11
 spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
21
-
22
-#spring.datasource.url=jdbc:mysql://localhost:3306/zipLine?useSSL=false
23
-#spring.datasource.username=root
24
-#spring.datasource.password=Calcifer1650
25
-#
26
-## The SQL dialect makes Hibernate generate better SQL for the chosen database
27
-#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
28
-#
29
-## Hibernate ddl auto (create, create-drop, validate, update)
30
-#spring.jpa.hibernate.ddl-auto = update
31
-#
32
-#logging.level.org.hibernate.SQL=DEBUG
33
-#logging.level.org.hibernate.type=TRACE