How to solve cors error in laravel and nodejs signalling app


i have a chat app built with laravel and My laravel app is located on one domain while my nodejs app is on another domain. Connecting to my nodejs signalling app gives a cors error while the nodejs app also returns cors error. Here is my nodejs app

"use strict";


const express = require('express');
const app = express();
const fs = require('fs');
const options = {
        key: fs.readFileSync(process.env.KEY_PATH),
        cert: fs.readFileSync(process.env.CERT_PATH)
const https = require('https').Server(options, app);
const io = require('')(https);'*:*');
const listner = https.listen(process.env.PORT, function() {
    console.log('Listening on ', listner.address().port);

//allow only the specified domain to connect
io.set('origins', process.env.DOMAIN + ':*');


app.get('/', function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
   // Add this
   if (req.method === 'OPTIONS') {
        res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE, OPTIONS');
        res.header('Access-Control-Max-Age', 120);
        return res.status(200).json({});

I have installed a cors middleware on my laravel backend but no difference whatsover. Any help will be appreciated

Source: Laravel

Categorised as cors, laravel, node.js, Tagged , , ,


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us