Javascript 无法向Eureka服务器注册React应用程序
错误: 取 'http://127.0.0.1:8761/eureka/apps/auth0-从源头对样品进行“反应” 'http://localhost:3000'已被CORS策略阻止:响应 飞行前请求未通过访问控制检查:否 “Access Control Allow Origin”标头出现在请求的服务器上 资源。如果不透明的响应满足您的需要,请设置请求的 模式设置为“无cors”,以获取禁用cors的资源 代码: Index.js(React应用程序)Javascript 无法向Eureka服务器注册React应用程序,javascript,java,reactjs,netflix-eureka,Javascript,Java,Reactjs,Netflix Eureka,错误: 取 'http://127.0.0.1:8761/eureka/apps/auth0-从源头对样品进行“反应” 'http://localhost:3000'已被CORS策略阻止:响应 飞行前请求未通过访问控制检查:否 “Access Control Allow Origin”标头出现在请求的服务器上 资源。如果不透明的响应满足您的需要,请设置请求的 模式设置为“无cors”,以获取禁用cors的资源 代码: Index.js(React应用程序) const PORT = pr
const PORT = process.env.PORT || 3000;
const eurekaHelper = require('./eureka-helper/eureka-helper');
const Eureka = require('eureka-js-client').Eureka;
// const PORT = 3000;
// const HOST = '0.0.0.0';
// example configuration
const client = new Eureka({
// application instance information
instance: {
app: 'auth0-react-sample',
hostName: 'localhost',
ipAddr: 'localhost',
//statusPageUrl: 'http://localhost:3000/',
port: 3000,
vipAddress: 'auth0-react-sample',
dataCenterInfo: {
name: 'default',
},
registerWithEureka: true,
fetchRegistry: true,
},
eureka: {
// eureka server host / port
host: 'localhost',
port: 8761,
servicePath: '/eureka/apps',
},
});
// Listen on a specific host via the HOST environment variable
var host = process.env.HOST || '0.0.0.0';
// Listen on a specific port via the PORT environment variable
var port = process.env.PORT || 3000;
const onRedirectCallback = (appState) => {
history.push(
appState && appState.returnTo ? appState.returnTo : window.location.pathname
);
};
// Please see https://auth0.github.io/auth0-react/interfaces/auth0provideroptions.html
// for a full list of the available properties on the provider
const config = getConfig();
const providerConfig = {
domain: config.domain,
clientId: config.clientId,
...(config.audience ? { audience: config.audience } : null),
redirectUri: window.location.origin,
onRedirectCallback,
};
client.start(error=>{
console.log(error || 'NodeJS Eureka started');
ReactDOM.render(
<Auth0Provider {...providerConfig}>
<App />
</Auth0Provider>,
document.getElementById("root")
);
});
eurekaHelper.registerWithEureka('auth0-react-sample', PORT);
serviceWorker.unregister();
const Eureka = require('eureka-js-client').Eureka;
const eurekaHost = (process.env.EUREKA_CLIENT_SERVICEURL_DEFAULTZONE || '127.0.0.1');
const eurekaPort = 8761;
const hostName = (process.env.HOSTNAME || 'localhost')
const ipAddr = '127.0.0.1';
exports.registerWithEureka = function(appName, PORT) {
const client = new Eureka({
instance: {
app: appName,
hostName: hostName,
ipAddr: ipAddr,
port: {
'$': PORT,
'@enabled': 'true',
},
vipAddress: appName,
dataCenterInfo: {
'@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
name: 'MyOwn',
},
},
//retry 10 time for 3 minute 20 seconds.
eureka: {
host: eurekaHost,
port: eurekaPort,
servicePath: '/eureka/apps/',
maxRetries: 10,
requestRetryDelay: 2000,
},
})
client.logger.level('debug')
client.start( error => {
console.log(error || "user service registered")
});
function exitHandler(options, exitCode) {
if (options.cleanup) {
}
if (exitCode || exitCode === 0) console.log(exitCode);
if (options.exit) {
client.stop();
}
}
client.on('deregistered', () => {
process.exit();
console.log('after deregistered');
})
client.on('started', () => {
console.log("eureka host " + eurekaHost);
})
process.on('SIGINT', exitHandler.bind(null, {exit:true}));
};