Reputation: 475
My socket.js file can not be found when my Node.js server runs on Heroku, however when it runs on localhost, it is found. In addition, although the app.js file is in the same directory with socket.js file, it can not be found. I've seen some posts suggesting to use
app.use('/', express.static(__dirname));
but i guess it is not the case here.
my index.html file :
<script src="/angular-socket-io/socket.js"></script>
<script src="/socket.js"></script>
<script src="/socket.io/socket.io.js"></script>
Amongst them, the only one couldnt be found is the second directory(/socket.js) which contains the 'socket factory'inside. My folder tree is as follows;
-app
--assets
---app.js
---socket.js
Any help please?
Upvotes: 2
Views: 1898
Reputation: 1199
My JavaScript file didn't initialize because of how I imported the JQuery script inside of my index.html. If your JavaScript file that contains JQuery is not initialized. Make sure to import it with HTTPS not HTTP.
WRONG :
<script src="http://code.jquery.com/jquery-3.5.1.js"></script>
CORRECT :
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
This solved my problem of missing the JavaScript file on Heroku.
Upvotes: 0
Reputation: 1428
Just add app.use(express.static(path.join(__dirname, 'app/assets')));
to your main code and after that you can use <script src="/socket.js"></script>
Upvotes: 2