반응형

작성일자 : 2022.06.19

환경 : vue 2, webpack-dev-server 4.8.1

시나리오 : 프록시를 활용하여 CORS 해결

 

관련 포스팅 : https://osc131.tistory.com/118

 

[Spring Boot] CORS 해결

[Spring Boot] CORS 해결 작성일자 : 2019.07.07 환경 : Spring Boot 2.1.6 다른 도메인에서의 자원을 호출하는 행위에 제한이 없을 경우 안전하지 않습니다. CORS (Cross-Origin Resource Sharing)는 이렇게..

osc131.tistory.com

 

1. webpack-dev-server 확인

 

package-lock.json 

"webpack-dev-server": {
	"version": "4.8.1"
    ...
    ...
}

사용하고 있지 않을 시 모듈 추가 필요

 

 

2.Proxy 설정 추가

 

vue.config.js

module.exports = {
  devServer: {
    proxy: {
	// /api 및 /api/* 요청에 대해 프록시 설정
      '/api': {	
        target: 'http://localhost:8080', // 프록시를 설정할 도메인
        changeOrigin: true,
      }, 
    },
  },
}

 

위 설정 이후 http://localhost:8080/api/* 에 대해 CORS 가 허용됨

 

 

* 주의 : 프록시 설정 이후 요청할 때 도메인 정보는 생략해야함

ex)

    const uri = '/api'; // 'http://localhost:8080/api' 로 작성 시 프록시 적용 X
    fetch(uri, {method: 'get'})
        .then(response => response.json())
        .then(response => {
            alert(response);
        })
반응형
반응형

전체 로그 :

  [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

 

조치 :

  프로젝트 바로 아래(package.json 위치)에 vue.config.js 생성 후 아래 옵션 추가

module.exports = {
    runtimeCompiler: true
}

 

반응형
반응형

작성일자 : 2020.06.16

 

IntelliJ 에서 Git 관련 작업이 무한 홀딩되는 상황 발생

 

 

상세 내용 : 

 

1. IntelliJ 에서 git repository 연결 Test 시 무한 홀딩

2. IntelliJ 에서 git 을 사용하여 소스 Clone 시 무한 홀딩

3. Spring 기반 자바 프로젝트를 IntelliJ 로 Open 시 무한 홀딩 (Vue 프로젝트는 열렸었음)

4. IntelliJ 설정에서 git 연결 확인 시 무한 홀딩 ( Versiont Control > Git > Test )

 

 

조치 내용 : 

 

IntelliJ 설정 ( File > Setting OR Ctrl+Alt+S ) > Version Control > Git > Path to Git excutable 수정

  

기존 - C:\Program Files\Git\git-cmd.exe 

수정 - C:\Program Files\Git\cmd\git.exe

 

Git 경로를 수정해준 뒤 Test 를 누르니, 정상적으로 버전 창 팝업 확인

 

 

reference :

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001211119-IntelliJ-hangs-on-Git-Identifying-Git-Version-

반응형
반응형

작성일자 : 2020.06.13

 

Stream 을 활용하여 List to Map 변환하는 과정에서 발생할 수 있는 키 중복 예외

 

예외 발생 예시

List<Integer> list = new ArrayList<Integer>(){{add(0);add(1);add(1);add(2);}};
// { 0, 1, 1, 2 }
        
        
Map<Integer, Integer> map = list.stream()
       .collect(Collectors.toMap(vo->vo, vo->vo));
// { {0,0}, {1,1}, {1,1}, {2,2} } 형태로 반환 -> key 1 중복 !!

 

수정

List<Integer> list = new ArrayList<Integer>(){{add(0);add(1);add(1);add(2);}};
// { 0, 1, 1, 2 }
        
        
Map<Integer, Integer> map = list.stream()
       .collect(Collectors.toMap(vo->vo, vo->vo, (oldValue, newValue) -> oldValue));
// { {0,0}, {1,1}, {2,2} } 형태로 반환 

// 기존 값을 유지할 경우
// .collect(Collectors.toMap(vo->vo, vo->vo, (oldValue, newValue) -> oldValue));
// 새로운 값을 유지할 경우
// .collect(Collectors.toMap(vo->vo, vo->vo, (oldValue, newValue) -> newValue));
반응형
반응형

// gradle.properties

org.gradle.jvmargs = -Xms512m -Xmx2048m

 

반응형
반응형

특정 Port 사용중인 프로세스 종료

 

작성일자 : 2019.12.26

시나리오 : WIndow에서 특정 포트번호를 사용중인 프로세스 종료

 

1. netstat -ano | findstr 'PortNumber'

2. PID 확인 ( 1. 명령어 결과의 우측 끝 5번째 인자 )

3. taskkill /F /PID 'PID'

 

 

반응형
반응형

[Spring Boot] CORS 해결

 

작성일자 : 2019.07.07

환경 : Spring Boot 2.1.6

 

다른 도메인에서의 자원을 호출하는 행위에 제한이 없을 경우 안전하지 않습니다. CORS (Cross-Origin Resource Sharing)는 이렇게 시스템 수준에서 타 도메인 간 자원 호출을 승인하거나 차단하는 것을 결정하는 것입니다. 여기서 Access-Control-Allow-Origin 란 CORS 의 헤더를 의미합니다.

Same Origin Policy에 의해 Script에 의한 cross-site http requests는 허용되지 않습니다. 즉 Ajax를 사용하여 통신을 하고 Front와 Back을 구별하여(ex Spring Boot + Vue.js) 개발하는 구조의 웹 서비스는 개발단계에서 서버와의 통신을 위해 추가로 설정이 필요합니다. 

 

GpConfig.java

package com.example.demo;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class GpConfig implements WebMvcConfigurer{
    @Override
    public void addCorsMappings(CorsRegistry cr) {
        cr.addMapping("/**")
            .allowedOrigins("http://127.0.0.1:8081")  // 허용할 주소 및 포트
            .allowedOrigins("http://localhost:8081");  // 허용할 주소 및 포트
    }

}

 

ProjectApplication.java 와 동일하거나 그 하위에 위치한 폴더에 작성

반응형
반응형

Failure to transfer commons-cli:commons-cli:pom:1.0 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact commons-cli:commons-cli:pom:1.0 from/to central (http://repo.maven.apache.org/maven2): Failed to create a selector. to http://repo.maven.apache.org/maven2/commons-cli/commons-cli/1.0/commons-cli-1.0.pom

 

1. .m2/repository 폴더를 삭제 후 ( default User/.m2 )

2. STS 프로젝트 우클릭 > Maven > Update Project... > Force update of Snapshots/Releases 

 

반응형
반응형

[ajax] Error code 0, error undefined


작성일자 : 2018년 11월 18일



1. 현상


HTML form 내에서 ajax를 사용하는 Javascript 함수 호출 시 간헐적 에러 발생


예시


HTML

<form onsubmit='JavaScript:example(data)> 

// submit 시 example 함수 실행 --------------------(2)


<!-- Logic -->


<button type="submit" value="submit"></button>

//button Click 시 form에 submit 전달 --------------------(1) 


</form>



Javascript

function example(data){


        // 아래 오류 발생 ajax 수행 ---------------(3)

$.ajax({

method : "GET",

url : "url",

data : {data: data},

success: function(){

//Logic

},

                // 에러 발생 후 아래 함수 실행 -----------(4)

error: function(request, status, error){ 


alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);  

                        // 실행 결과 code 0, undefined Error 발생 문구 alert --------------- (5)


}

});



alert 내용

code : 0

message :       

error : undefined




2. 원인


 AJAX 응답을 받기 전에 브라우저 새로 고침이 트리거 된 경우 발생


즉 Submit에 의해 form의 (action 미 설정 시 현재위치 새로고침) action과, ajax 호출 함수인 example이 트리거 되고,

example 함수에 의한 ajax 수행 중 ajax 결과를 받기 전에 action에 의해 새로고침이 트리거 될 때 발생


응답 속도에 따라 동일한 Flow가 success가 될 수도, Fail이 될 수도 있는 상황




3. 해결방안


form에 의한 action을 없애고, ajxa 결과 반환 후 action을 수행하도록 설정


수정 후 예시


HTML

<form onsubmit='JavaScript:example(data, event)>  // event 인자 추가

// submit 시 example 함수 실행 --------------------(2)


<!-- Logic -->


<button type="submit" value="submit"></button>

//button Click 시 form에 submit 전달 --------------------(1) 


</form>



Javascript

function example(data, event){

        event.preventDefault(); // event 중단 함수


        // 아래 오류 발생 ajax 수행 ---------------(3)

$.ajax({

method : "GET",

url : "url",

data : {data: data},

success: function(){

// Logic

                        // Ajax 응답 후 수행 할 Action 추가

},

                // 에러 발생 후 아래 함수 실행 -----------(4)

error: function(request, status, error){ 


alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);  

                        // 실행 결과 code 0, undefined Error 발생 문구 alert --------------- (5)


}

});





4. 참고


https://stackoverflow.com/questions/2000609/jquery-ajax-status-code-0

반응형
반응형

[postgreSQL] FATAL:  pg_hba.conf rejects connection for host ‘IP’

 

작성일자 : 2018 0927

환경 : PostgreSQL 9.2.14, AWS Linux

 


1. 현상 :


사용하던 데이터베이스의 접속이 거부 된다는 로그 확인


FATAL:  pg_hba.conf rejects connection for host "127.0.0.1", user "postgres", database "postgres"

 



- 설정 확인

PGDATA/data/ > vi pg_hba.conf



 

추가한 적 없는 옵션이 상단에 추가된 것을 확인


host all postgres 0.0.0.0/0 reject

host all pgdbadm 0.0.0.0/0 md5

# 기본계정인 postgres 계정으로 접속을 제한하고 pgdbadm 계정으로 접속 허용


pgdbadm 계정은 최근 crypto-mining 공격 계정으로 알려져 있다.

 

 


2. 해결 방안 :



추가 된 옵션을 주석 처리 후 PostgreSQL 재시작

 



3. 권고 사항 :



서비스 시 기본 계정인 postgres 계정 외 계정 사용


pg_hba.conf 파일 수정 제한

 



4. 참조


https://dba.stackexchange.com/questions/215294/why-does-pg-hba-conf-sometimes-have-random-rules-added-to-it-postgresql?rq=1


반응형

+ Recent posts