2017-11-17 16 views
0

이 코드 (angular2) 데와 외부 소스입니다 :더 JWT 토큰 인증되지는 angular2

let headers = new Headers({'Content-Type': 'application/json'}); 
    headers.append('Authorization', this.authService.currentUser.token) 
    let options = new RequestOptions({ headers: headers }); 
    return this.http.get(this.url + 'quote/' , options) 

this.url = '/' (로컬 요청), 내가 헤더에 권한이 : enter image description here


this.url = 'http://212.227.201.82/' 일 때 인증 토큰이 사라집니다.

enter image description here

어떻게 외부 요청에 대한 헤더 인증을 포함 할 수 있습니다? 당신의 도움에 감사합니다

답변

1

나는이 문제점을 발견했습니다! 프론트 엔드가 아닌 백엔드! CORS (크로스 원산지 자원 공유는) ExpressJS와

EG API를 활성화해야합니다 :

$ npm install cors 

간단한 사용법 (모든 CORS 요청을 사용)를

var express = require('express') 
var cors = require('cors') 
var app = express() 

app.use(cors()) 

app.get('/products/:id', function (req, res, next) { 
    res.json({msg: 'This is CORS-enabled for all origins!'}) 
}) 

참조 : Allow multiple CORS domain in express js/How to allow CORS?/https://github.com/expressjs/cors