(IONIC 2) Issue: error when trying to integrate socket.io with express, receiving a 404 (Not Found) error when attempting to connect to http://localhost:3000/socket.io/?EIO=3&transport=polling&t=LvraMV

I encountered an issue while attempting to connect my node server with Ionic2,

Here is some background information:

1. I am developing the node server on my personal laptop. 2. When running 'ionic serve', everything functions normally without any issues.

The problem arises when I try to run it on an Android device using the command ionic cordova run android. In this case, I encounter multiple errors and upon checking the console for details, I see the following message:

GET 404 (Not Found)

Below is a snippet of the code causing the issue:

var socket = require('socket.io'),
http = require('http'),
server = http.createServer(),
socket = socket.listen(server);

socket.on('connection', function(connection) {
    console.log('User Connected');

    connection.on('sendid', function(id){
        socket.emit('id', id);
        console.log('Triggered ID : ', id);
    });

    connection.on('message2', function(msg){
        console.log('Triggered msg :', msg);
        socket.emit('message2', msg);
    });

    connection.on('message', function(msg){
        console.log('Triggered msg :', msg);
        socket.emit('message', msg);
    });
});

server.listen(3000, function(){
    console.log('Server started');
});

And here is the snippet from my Ionic2 application where I attempt to access the server:

this.statisticServer="http://myIpIsHere:3000/";
console.log('server :', this.statisticServer );
this.socket = io(this.statisticServer);

Answer №1

Issue resolved,

I incorporated a whitelist plugin,

Ran the command: cordova plugin add cordova-plugin-whitelist --save

Hopefully this solution benefits others in the future.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Next.js applications hosted on Vercel servers may have distinct process.env.PWD values for static routes compared to dynamic routes

I'm currently utilizing the app router and deploying on Vercel. Within the root of my project, I have a directory named blog where I store markdown files. When accessing them locally, I use: ./blog/a-blog-post.md. This method works well for both dynam ...

In Jenkins, there do not exist any configurations specifically for NodeJS installations

I've been struggling with this issue for a while now and haven't been able to find a solution online. Using Jenkins as my CI tool and Git as the source of code. The build trigger is set to another build stability. The plugin manager indicates th ...

Redis is prepared and awaiting authorization for authentication. ReplyError: NOAUTH Authentication needed

When attempting to connect to a Redis instance hosted on redislab, an error message is received indicating Redis ready ReplyError: NOAUTH Authentication required. const pubClient = createClient({ url: `${config.redisLabHost}:${config.redisLabPort}` }); pub ...

Starting a new container causes another container to halt

Having created two basic MEAN stack apps that share a common MongoDB database, I successfully dockerized both applications. Issue: When starting the first mean stack container (example-app-1) using docker-compose up -d --build The container runs smoot ...

What could be causing Laravel Sail NPM to display the error message 'unsupported version of Node.js'?

In the midst of a Laravel 8 project using Docker, I find myself knee-deep in SCSS design. However, a hurdle arises when attempting to compile my SCSS files. NPM insists that my Node version is outdated at 12.x, even though within my container I am actually ...

What is the process for importing a server app in Chai for making requests?

I am looking to conduct tests on my node express server, but the way this application starts the server is as follows: createServer() .then(server => { server.listen(PORT); Log.info(`Server started on http://localhost:${PORT}`); }) .catch(err =& ...

How to prevent users from accessing the app through standard web browsers in an Express/Electron application

My setup involves an express server that serves my angular front end at http://localhost:9000 Utilizing electron as a desktop client is part of my project. I am aiming to restrict users from accessing the application through any browser except electron. ...

The files _buildmanifest.js and _ssgmanifest.js could not be loaded. The server returned a 404 error, indicating that the resources were not found

Upcoming: 12.3.4 React Version: 17.0.2 Node Version: 16.13.1 An error is persisting in my Next.js application where the console displays the following message on all pages I load: 404 Failed to load resource: the server responded with a status of 404 ( ...

What is the correct method for orchestrating API requests during deployment with create-react-app and an ExpressJS backend?

I have encountered a problem while trying to deploy my react application to the server. After deployment, when the app attempts to make API calls to the same server, an error occurs: Cross-Origin Request Blocked: The Same Origin Policy disallows reading ...

Mongoose reverse population involves querying a document's references

I am currently exploring ways to populate my business orders using the businessId property in my orders collection. I attempted a solution but I am facing difficulties making it work. https://www.npmjs.com/package/mongoose-reverse-populate If you have an ...

After clicking on the checkbox, req.body.task becomes undefined

Whenever I click on the checkbox, the value of req.body.task returns as undefined. <input type="checkbox" name="task" autocomplete="off" checked="" onchange="onToDochange({{id}})"> This function is triggered by a change event on the checkbox and it ...

Hyperledger Fabric: ERROR! 404 - The requested fabric-chaincode-api package (version 1.4.5) could not be found on the npm registry

I created my chaincode using Node.js API and now I'm attempting to perform the instantiation process. docker image: hyperledger/fabric-peer:1.4.5 In my package.json file, here is what I have included: { "name": "democontract", "version": "1 ...

Encountered an error during the production build of NEXTJS, where it panicked due to the global thread pool not being initialized

While hosting my app on Heroku and running git push heroku main, I encountered the following error: panicked at 'the global thread pool has not been initialized.: threadpool builderror { kind: ioerror(error { kind: unsupported, message: "operatio ...

Error received on Node.js controller when calling Jquery getJSON from Ajax form

I have a Node.js / Sails.js application with a client-side form that submits to a Controller using jQuery ajax: $(function () { $("form").submit(function (e) { e.preventDefault(); var form = $(this); $.ajax({ url: ...

Express app: the ideal location to implement a closed-loop temperature control system

I am relatively new to working with express.js, having only created some basic client/server apps in the past. Currently, I am looking to develop a temperature controller using a PID component. However, I am struggling to grasp the architecture of express ...

Deploy NextJs on an IIS server

Greetings! I have a colleague who has a node.js (next.js) website that runs smoothly when built and started through the console (npm run build and npm start). We have now hosted it on an Azure VM (Windows Server 2016 IIS, with iisnode and urlrewrite inst ...

Issue: ENOENT, unable to locate 'C:UsersAliAppDataRoaming pm'

Upon trying to initialize npm in a fresh Node.js installation, I encountered the following error: Error: ENOENT, stat 'C:\Users\Ali\AppData\Roaming\npm' ...

How can I see a list of all background tasks and threads running in a node.js application?

My AWS setup consists of a nodejs + mysql application running on Windows (EC2, RDP). I'm concerned that there may be threads/loops/jobs running in the background as a result of my coding errors. Is there a way to monitor and track these background pro ...

Using Bazel, Angular, and SocketIO Version 3 seems to be triggering an error: Uncaught TypeError - XMLHttpRequest is not recognized

Looking to integrate socket.io-client (v3) into my Angular project using Bazel for building and running. Encountering an error in the browser console with the ts_devserver: ERROR Error: Uncaught (in promise): TypeError: XMLHttpRequest is not a constructor ...

Why does npm install a different version of a dependency than what is listed in the package-lock.json file?

node -v v17.2.0 npm -v 8.1.4 package.json { "name": "untitled", "version": "0.0.0", "private": true, "devDependencies": { "stylelint": "^14.1.0" } } npm i ...