0

My server side application is hosted on heroku: https://shielded-dusk-72399.herokuapp.com/

Relevant code looks like this:

const
    express = require('express'),
    app = express(),
    server = require('http').createServer(app),
    io = require('socket.io').listen(server),
    port = process.env.PORT || 8080

server.listen(port, (err) => {
  console.log(err || 'listening on my very special port ' + port)
})

In my heroku logs this gets logged: "listening on my very special port 28428"

Now on my client application:

Currently my client application is running on port 8080

In my index.html:

<script>/socket.io/socket.io.js" charset="utf-8"></script>

When I go to localhost:8080 I get the following errors:

Cannot GET http://localhost:8080/socket.io/socket.io.js

Other Attempts:

<script src="https://shielded-dusk-72399.herokuapp.com:28428/socket.io/socket.io.js" charset="utf-8"></script>

Cannot GET https://shielded-dusk-72399.herokuapp.com:28428/socket.io/socket.io.js net::ERR_CONNECTION_REFUSED

<script src="https://shielded-dusk-72399.herokuapp.com:8080/socket.io/socket.io.js" charset="utf-8"></script>

Cannot GET https://shielded-dusk-72399.herokuapp.com:8080/socket.io/socket.io.js net::ERR_CONNECTION_REFUSED

And then I copied ./node_modules/socket.io-client/dist/socket.io.js to resources/js and get this error:

Cannot GET http://localhost:8080/resources/js/socket.io.js 404 (Not Found)

Any ideas?

I've used these all as references and still coming up short:

node.js /socket.io/socket.io.js not found

Node.js /socket.io/socket.io.js not found express 4.0

Can't get socket.io.js

Community
  • 1
  • 1
user2456977
  • 3,830
  • 14
  • 48
  • 87

1 Answers1

0

You need to specify from where to serve your static js file. For instance, if you placed the socket.io.js file in your /resources/js/ folder, add the following:

app.use('/resources', express.static(path.join(__dirname, 'resources')))

Then your file will be available on http://localhost:8080/resources/js/socket.io.js

mineralwasser
  • 771
  • 5
  • 16