Here is the scenario: while running my server on node.js locally, the client code successfully retrieves data from the server. However, upon pushing the code to the live server, the client receives a
/getSettings 500 (Internal Server Error)
. The main index route '/'
functions properly, indicating that the endpoint is accessible. So why is the /getSettings route causing an error?
Node.js serves as the runtime for my server.
SERVER code (app.js):
const express = require('express');
var path = require('path');
var Config = require('./config.js'), conf = new Config();
const app= express();
const port = 3000;
app.listen(port, function(error){
if(error) {
console.log('Server failed to listen: ', error)
} else{
console.log('Server is listening on port: ' + port)
}
});
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.get("/getSettings", function(req, res){
res.json({ configuration: conf });
});
app.use(express.static(path.join(__dirname, 'public')));
CLIENT Code:
<script>
window.onload = function()
{
$.get("/getSettings", function( data )
{
//do stuffs
});
};
</script>