2014-11-26 5 views
1

heroku에서 호스팅되는 서버가있는 노드 응용 프로그램이 있습니다. 약 10 또는 15를 보낼 때까지 내 모든 요청이 성공적입니다. 그런 다음 CORS 오류를 받기 시작합니다. 왜 이런 일이 일어날 지 모른다고 생각하세요?노드 : CORS 가끔씩 실패합니다

사용해보기. http://danielrasmuson.github.io/

내 'CORS 사용 코드'입니다. 나는이 시점에서 몇 가지 것을 시도하고있다.

var app = express(); 
app.use(cors()); 

app.all('/*', function(req, res, next) { 
    res.header("Access-Control-Allow-Origin", "*"); 
    res.header("Access-Control-Allow-Headers", "X-Requested-With"); 
    next(); 
}); 

app.use(function(req, res, next) { 
    res.header("Access-Control-Allow-Origin", "*"); 
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); 
    next(); 
}); 
+0

하면 브라우저에서 CORS 오류를 얻을, 당신은 서버에서 HTTP 헤더를 검사 했습니까? Chrome 디버거의 네트워크 탭에 모두 표시됩니다. – jfriend00

+0

리소스를로드하지 못했습니다. 서버가 503 (서비스를 사용할 수 없음) (인덱스) : 1 상태로 응답했습니다. 1 XMLHttpRequest에서 https://aqueous-temple-8608.herokuapp.com/pills를로드 할 수 없습니다. 'Access-Control-Allow-Origin'헤더가 요청 된 리소스에 없습니다. 따라서 'http://danielrasmuson.github.io'는 액세스가 허용되지 않습니다. 응답의 HTTP 상태 코드는 503입니다. –

답변

1

너무 늦기없는 경우 내가하지 알고하지만 어쩌면이 도움이 될 수 있습니다 를이 코드와 같은 문제가 있었다 :

router.post('/create', function (req, res, next) { 
    password(req.body.user_password).hash(function (error, hash) { 
     if (error) 
      throw new Error('Something went wrong!' + error) 

     console.log(req.body); 
     req.body.user_password = hash; 
     User.create(req.body, function (err, post) { 
      if (err) return next(err); 
      console.log(post); 
      res.json(post); 
     }); 
    }); 

}); 
(때때로 나는 503 Heroku가 오류와 고르의하는 오류를 가지고) 나는 그것을 변경하는 경우

는 :

router.post('/create', function (req, res, next) { 
    password(req.body.user_password).hash(function (error, hash) { 
     if (error) { 
      throw new Error('Something went wrong!' + error); 
     } else { 
      req.body.user_password = hash; 
      User.create(req.body, function (err, post) { 
       if (err) { 
        throw new Error('Something went wrong!' + err); 
       } else { 
        res.json(post); 
       } 
      }); 
     } 
    }); 

}); 

더 이상 때때로 코드와 고르 실패하지 않습니다.

마침내 헤로큐가 아닌 노드 응용 프로그램의 문제인 것 같습니다.

건배 투입 Blažej

+0

Thanks @ Błażej Grzeliński. 나는이 오류로 실행할 수있는 예외를 올바르게 처리하지 않으면 귀하의 권리라고 생각합니다. –

관련 문제