여유상점 10_30 24) Cafe24 : Revising Some codes after upload_2)

오범준·2020년 10월 30일
0

I am dealing with the same problem written in previous article ( Loginned, but passport not deserializing )

Trial 2) Setting CORS in Server

link1 ) https://ko.javascript.info/fetch-crossorigin
link2 ) http://guswnsxodlf.github.io/enable-CORS-on-express

Let's See what CORS is

CORS = Cross-Origin-Resourse-Sharing

* What is Origin(출처)

one url such as (www.google.com) seems like one componenent but is is comprised of multiple components

it's not included in image, but port such as ':80', ':43' is also included

That is, above url includes all the basic elements to reach the location of the server( If the port is empty or not given, port 80 is assumed )

You can simply check where the application is running

console.log(location.origin);

Okay, Now I know what the 'origin' is,
Then, How do we decide whether origin is same or not

It's very simple, among the elements of url,
if 3 things
1) Scheme
2) Host
3) Port

For Example,
" https://evan-moon.github.io:80"
1) Scheme : https://
2) Host : evan-moon.github.io
3) Port :80

It is regarded as same origin, even if other elements differ

Anyway...

Even if It does not seem to be related with cors issue, since I am using the same origin,
I added below code to main server code

app.use(cors({credentials: true, origin: '~'}));

CORS란 무엇인가
CORS란 Cross Origin Resource Sharing의 약자로, 현재 도메인과 다른 도메인으로 리소스가 요청될 경우를 말한다. 예를 들어, 도메인 http://A.com 에서 읽어온 HTML페이지에서 다른 도메인 http://B.com/image.jpg를 요청하는 경우를 말한다. 이런 경우에 해당 리소스는 cross-origin HTTP 요청에 의해 요청된다. 보안 상의 이유로, 브라우저는 CORS를 제한하고 있다.

하지만 SPA(Single Page Application)의 경우에는, RESTful API를 기반으로 비동기 네트워크 통신을 하기 때문에 API 서버와 웹 페이지 서버가 다를 수 있다. 이런 경우에 API 서버로 요청을 할 시에 CORS 제한이 걸리게 된다.

Trial 3) 304 Status Code

When I checked the status code, when problemn occurred,
I found out that status code is 304

What is 3xx ?
3xx: Redirection - Further action must be taken in order to complete the request
( 리다이렉션 - 요청이 완수되기 위해서 추가적인 동작이 이뤄져야 함 )

That is, it occurs when the requested result is not different from pre-request result.

That is , it's because it's using cached page

link related with cache : https://cyberx.tistory.com/9

Trial 4) Going Through the basic process of the entire passport js

link 1 : https://github.com/jaredhanson/passport/issues/482

profile
Dream of being "물빵개" ( Go abroad for Dance and Programming)

0개의 댓글