I have a Node Js app with a React Frontend deployed as an App. Unfortunately Im having a hard time making socket.io work outside of localhost… Im using ${APP_URL}/node as a route for backend and it is running on port 80.
const app = express();
const server = http.createServer(app);
export const io = new Server(server, {
cors: {
origin: allowedOrigins,
methods: ['GET', 'POST'],
},
});
// Listen for when the client connects via socket.io-client
io.on('connection', socket);
const connectServer = async () => {
app.set("view engine", "ejs");
app.use(cookieParser());
app.use(credentials);
app.use(cors(corsOptions));
app.use( express.urlencoded({limit: '50mb', extended: true }));
app.use((req, res, next) => {
if (req.originalUrl === '/stripeHook') {
next();
} else {
express.json({ limit: '50mb' })(req, res, next);
}
});
app.use(express.static('static'))
const PORT = process.env.PORT || 80;
server.listen(PORT, () => console.log(`Server is running on port ${PORT}.`));
};
connectServer();
And on client side Im using a hook
const BASE_URL = process.env.REACT_APP_SOCKET_URL;
socket = io(BASE_URL);
if(userId)socket.emit("live", userId)
Im getting POLLING 200 response in my network tab but the response is ‘You need to enable javascript’.
Can someone help me out! Appreciate any help
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I’m curious if you ever figured out an answer to this? Looking to do the same.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.