2016-09-10 3 views
0

내 클라이언트 응용 프로그램에서 요청 방법 "OPTIONS"를 보낼 때마다 내 명시 적 앱 (파일 제공 용)이 300을 반환합니다.특급 반환 상태 300 옵션에서

Chrome console

Chrome network

이 보이지 않는다 : 나는 임의의 "300"을 얻을 수 (크로스 - 도메인입니다) 내 다른 클라이언트에서

import express from 'express' 
import * as middleware from './middleware' 
let App = express(); 

// Logger 
App.use((req, res, next) => { 
    console.log(req.method, req.url) 
    next() 
}) 

// Cors 
App.use((req, res, next) => { 
    res.header("Access-Control-Allow-Origin", "*"); 
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"); 
    next(); 
}); 

// Middleware 
// App.use('/', middleware.authenticate) 

// Root 
App.get('/', (req, res) => { 
    res.send('Test!') 
}) 

App.listen(3030,() => { 
    console.log('It\'s working!') 
}) 

: 여기에 코드입니다 "300"오류가 발생할 때까지의 실제 패턴이 될 수 있습니다.

import axios from 'axios' 
import Store from '../store' 

let api_url = 'http://127.0.0.1:8000/api' 
let media_url = 'http://127.0.0.1:3030' 

let urls = { 
    api: api_url, 
    media: media_url, 
} 

const Request = { 
    GET: function(url, server) { 
    this.getAuthtoken(); 
    return axios.get(urls[server || 'api'] + url, this.config) 
    }, 
    getAuthtoken: function() { 
    let token = Store.getState().auth.key; 
    if (token !== null) { 
     this.config.headers['Authorization'] = "Token " + token 
    } else { 
     delete this.config.headers.Authorization; 
    } 
    }, 
    config: { 
    headers: {} 
    } 
} 

// The request 
Request.GET('/', 'media').then((response) => { 
    console.log(response) 
}) 
+0

귀하의 고객은 무엇을하고 있습니까? 코드를 게시 할 수 있습니까? – peteb

+0

@peteb 예, 제 편집 참조. –

+0

이 동작은 실제로 의미가 없습니다. AFAICS, Express는 명시 적으로 그렇게하지 않는 한 300 개의 응답을 전송하지 않으며 게시하는 코드는 그렇게하지 않습니다. – robertklep

답변

0

크롬이 하나 잘못했다 보인다 여기

내 클라이언트가 보낸 요청에 대한 코드입니다. 내 확장 프로그램으로 인해 문제가 발생하지 않았지만 모든 데이터를 지우고 Chrome을 재설정하면 문제가 해결되었습니다.