我正在尝试将Nodejs后端api与Angular集成。我已经在后端应用程序上实现了passpor-google,passport-github,passport-twitter策略。
我的后端应用程序url是http://localhost:3000,我的前端应用程序url是http://localhost:4200
护照路线
authRouter.get('/github', passport.authenticate('github'));
authRouter.get(
'/github/callback',
passport.authenticate('github', {
failureRedirect: 'http://localhost:4200/login',
}),
authController.sendJWTToken
);当我从前端应用程序发送请求时,它会显示CORS错误
AuthService.ts
githubAuth(): Observable<LoginRsp> {
return this.httpClient.get<LoginRsp>(
`${environment.api_url}/auth/github`
);
}我已经在Nodejs项目中添加了CORS。我该如何解决这个问题,请帮帮我
发布于 2018-05-13 23:27:05
使用cors模块cors或使用express cors中间件express cors
app.use(cors());之后的任何其他路由
const users = require('./routes/users');或者尝试将cors中间件移至顶层
发布于 2018-05-14 17:55:57
你可以像下面的图片那样做

发布于 2018-07-10 15:01:00
在AuthService.ts中只需使用window.location.href='{environment.api_url}/auth/github‘
https://stackoverflow.com/questions/50317575
复制相似问题