Below is code where the client is trying to get data from the server. Locally running my server on node.js, this works great. However, when I push to my server, I get /getSettings 500 (Internal Server Error)
. My index gets hit when the other request is made '/'
so I know the endpoint can be hit. But why not this other get?
Node.js is running on my server as a runtime.
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(require, response){
response.json({ configuration: conf });
});
app.use(express.static(path.join(__dirname, 'public')));
CLIENT Code:
<script>
window.onload = function()
{
$.get("/getSettings", function( data )
{
//do stuffs
});
};
</script>
from javascript .get function works in development but not production
No comments:
Post a Comment