so i was wondering is it possible to send cross-domain requests in an angular services? because i have service but when i send a rquest i get the following error:
so i check the request itself :
and no cors has been enabled, then i tried adding it to the backend because that i an answer that comes up a lot but it still didnt help. so here is my code :
this.http.get("https://www.linkedin.com/oauth/v2/accessToken?grant_type=client_credentials&client_id=[ID]&client_secret=[SECRET]").subscribe((data:any) => console.log(data));
i was wondering can you add an header to the get request ? if any more details are necessary just write a comment and i will edited in here.
EDIT:
my back-end
var app = express();
app.use((req, res, next) => {
res.append('Access-Control-Allow-Origin', ['*']);
res.append('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.append('Access-Control-Allow-Headers', 'Content-Type');
next();
});
var mongoose = require('mongoose');
mongoose.connect('MONGO_URL', { useNewUrlParser: true, promiseLibrary: require('bluebird') })
.then(() => console.log('connection successful'))
.catch((err) => console.error(err));
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'dist/OMRT')));
app.use('/', express.static(path.join(__dirname, 'dist/OMRT')));
app.use('/dashboard', express.static(path.join(__dirname, 'dist/OMRT')));
app.use('/api', apiRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.sendStatus(err.status);
});
module.exports = app;
i use express/node.js backend and the above snippet i used to add an header to allow the origin. i added my localhost because of the error.
redirect-URLS: