Arkadaşlar merhaba. React ve Springboot ile bir web sitesi yaptım kendime. İlgili çıktıları aldım ve sunucuda güzel bir şekilde çalıştırdım. Admin panelimde içerikler ekliyorum, sitemde gözüküyor güzel.
Daha sonra Brave dediki, "bu site güvenli değil". Ben de Cloudflare'ye sunucumu, alan adının DNS'lerine de Cloudflare ekledim.
Cloudflare'den SSL/TLS ayarı default olarak "flexiable" idi. Ondan Springboot izin vermedi bağlantılar, blokladı. "Full' de ise site açılmıyor. Ben de "Off" seçeneği ile kullamıyorum ama "güvenli değil" hatası veriyor Brave. Ayrıca telefondan da siteye eriştiğimiz zaman veri tabanı ile bağlantı kurmuyor.
İlgili kodlarım;
Controller.java
WebConfig.java
Application.yaml
React: Service.js
Tarayıcının verdiği hata;
"Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR https://xxx.x.x.xxx:8080/api/content"
Arkadaşlar eğer Service.js'in adresini "http://" ile başlatırsam da bu hatayı veriyor;
" GET http://xxx.xxx.xxx.xxx:8080/api/content net::ERR_FAILED 500"
Başka bir hata yok. (kusura bakmayın IP adresini gizlemem gerekiyor).
@bitwise @count
@Lordxe
Daha sonra Brave dediki, "bu site güvenli değil". Ben de Cloudflare'ye sunucumu, alan adının DNS'lerine de Cloudflare ekledim.
Cloudflare'den SSL/TLS ayarı default olarak "flexiable" idi. Ondan Springboot izin vermedi bağlantılar, blokladı. "Full' de ise site açılmıyor. Ben de "Off" seçeneği ile kullamıyorum ama "güvenli değil" hatası veriyor Brave. Ayrıca telefondan da siteye eriştiğimiz zaman veri tabanı ile bağlantı kurmuyor.
İlgili kodlarım;
Controller.java
Java:
package com.tensa.proje.controller;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import com.tensa.proje.entityDTO.ContentDTO;
import com.tensa.proje.service.ContentService;
import lombok.AllArgsConstructor;
@RestController
@RequestMapping("/api/content")
@AllArgsConstructor
public class ContentController {
private ContentService service;
@GetMapping("{id}")
public ResponseEntity<?> getContent(@PathVariable("id") Long id) {
ContentDTO contentDTO = service.getContent(id);
if(contentDTO != null) {
return ResponseEntity.ok(contentDTO);
}else {
return new ResponseEntity<>
( "Not found content by id: "+ id, HttpStatus.NOT_FOUND);
}
}
@PostMapping
public ResponseEntity<?> createContent(@RequestBody ContentDTO content){
ContentDTO contentDTO = service.createContent(content);
if(contentDTO != null) {
return ResponseEntity.ok(contentDTO);
}else {
return new ResponseEntity<>("Not crate content", HttpStatus.BAD_REQUEST);
}
}
@GetMapping
public ResponseEntity<?> getContents(){
List<ContentDTO> contents = service.contents();
if(contents != null) {
return ResponseEntity.ok(contents);
}else {
return new ResponseEntity<>
( "Conttens Not Found", HttpStatus.NOT_FOUND);
}
}
@PutMapping("{id}")
public ResponseEntity<?> updateContent(@PathVariable("id") Long id,
@RequestBody ContentDTO contentDTO){
ContentDTO content = service.updateContent(id, contentDTO);
if(content != null) {
return ResponseEntity.ok(content);
}else {
return new ResponseEntity<>
( "Conttens Not Found", HttpStatus.NOT_FOUND);
}
}
@DeleteMapping("{id}")
public void deleteContent(@PathVariable("id") Long id) {
service.deleteContent(id);
}
}
WebConfig.java
Java:
package com.tensa.proje.controller;
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("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*")
.allowCredentials(true);
}
}
Application.yaml
YAML:
spring:
datasource:
driverClassName: org.h2.Driver
url: jdbc:h2:file:./dataBase
username: root
password: 1234
http:
encoding:
force: true
charset: UTF-8
enabled: true
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
generate-ddl: true
show-sql: true
React: Service.js
Kod:
import React from 'react';
import axios from 'axios';
import Base from 'antd/es/typography/Base';
const BASE_URL = 'https://xxx.x.x.xxx:8080/api/content';
export const listContents = () => axios.get(BASE_URL);
Tarayıcının verdiği hata;
"Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR https://xxx.x.x.xxx:8080/api/content"
Arkadaşlar eğer Service.js'in adresini "http://" ile başlatırsam da bu hatayı veriyor;
" GET http://xxx.xxx.xxx.xxx:8080/api/content net::ERR_FAILED 500"
Başka bir hata yok. (kusura bakmayın IP adresini gizlemem gerekiyor).
@bitwise @count
@Lordxe
Son düzenleme: