2017-03-21 5 views
-1

Ich habe eine AngularJS und NodeJS (API) -Anwendung. Ich hatte bereits CORS auf meinem NodeJS mit CORS() Nodejs-Bibliothek aktiviert.AngularJS NodeJS Cors Probleme hinter Firewall

Ich habe die erforderlichen Header eingefügt, um auch CORS zu aktivieren.

Ich habe CORS Problem nur, wenn ich die Website von meinem Firmencomputer zugreifen. Es funktioniert gut von meinen Personal Computern. Kann mir bitte jemand sagen, was ich falsch mache. Jede Hilfe oder Anregung bitte.

Chrome Konsolenprotokolle:

-------------------- Headers ----------------- ----

Allgemein:

Request URL:www.example.com:81/api/getdata 
Request Method:GET 
Status Code:503 Service Unavailable 
Remote Address:111.111.11.111:81 

Antwort-Header:

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
    Connection:close 
    Content-Length:973 
    Content-Type:text/html; charset=UTF-8 
    Expires:Thu, 01 Jan 1970 00:00:00 GMT 
    P3P:CP="CAO PSA OUR" 
    Pragma:no-cache 

Anforderungsheader:

Accept:application/json, text/plain, */* 
    Accept-Encoding:gzip, deflate, sdch 
    Accept-Language:en-US,en;q=0.8 
    Connection:keep-alive 
    Host:www.example.com:81 
    Origin:http://www.example.com 
    Referer:http://www.example.com/ 
    User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 

-------------------- Antwort: --------------- -----

<html> 
<head> 
    <title>Web Page Blocked</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 
    <meta name="viewport" content="initial-scale=1.0"> 
</head> 
<body bgcolor="#e7e8e9"> 
<div id="content"> 
<h1>Web Page Blocked</h1> 
<p>Access to the web page you were trying to visit has been blocked in accordance with company policy. Please contact your 

system administrator if you believe this is in error.</p> 
<p><b>User:</b> </p> 
<p><b>URL:</b> www.example.com:81/api/getdata </p> 
<p><b>Category:</b> unknown </p> 
</div> 
</body> 
</html> 

Browser Console Fehler:

XMLHttpRequest cannot load http://www.example.com:81/api/getdata . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://www.example.com ' is therefore not allowed access. The response had HTTP status code 503.

------ ----- EDIT Hier ist die cors() ich bin vorbei.

app.options('*',cors()); 

app.use(function (req, res, next){ 

    res.header("Access-Control-Allow-Origin", "*"); 
    res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE"); 
    res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE"); 
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With,Content-type, Accept"); 

    res.header("Access-Control-Allow-Credentials", true); 

    next(); 

}); 
+1

Meine Vermutung wäre, dass Ihr Unternehmen blockiert Port 81. Nichts mit Ihrer Anwendung zu tun . – Duncan

+0

Danke für die Antwort, ich würde es mit einem anderen Port versuchen. – user3479754

Antwort

-1

Es ist entweder ein Problem mit der Firewall Ihres Unternehmens oder ein CORS-Problem. Versuchen Sie, jede Ursprung in CORS-Modul zu übernehmen:

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

var corsOptions = { 
    origin: '*', 
    optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204 
}; 

app.get('/products/:id', cors(corsOptions), function(req, res, next){ 
    res.json({msg: 'This is CORS-enabled for every origin.'}); 
}); 

app.listen(80, function(){ 
    console.log('CORS-enabled web server listening on port 80'); 
}); 

Jetzt sollten Sie Response-Header wie folgt erhalten:

HTTP/1.1 200 OK 
Access-Control-Allow-Origin: * 
Keep-Alive: timeout=2, max=100 
Connection: Keep-Alive 
Transfer-Encoding: chunked 
Content-Type: application/json 

Wenn es immer noch nicht funktioniert, dann Port 81 gesperrt werden müssen.

Eine andere Möglichkeit ist, dass der Proxy Ihres Unternehmens einige Header entfernt oder Blöcke, die erklären könnte, warum Access-Control-Allow-Origin: www.example.com nicht in Ihrer Antwort-Header ist

+0

Danke für die Antwort, ich würde versuchen, Ihre Vorschläge. – user3479754

+0

Ich habe cors() wie oben angegeben hinzugefügt, aber die Kopfzeile wird von der Firewall entfernt. Wie lösen wir das Cors-Problem, wenn Ihre Website von einem Firmencomputer aus aufgerufen wird? – user3479754