I’m using GoDaddy shared hosting, and I was able to follow these very helpful steps to SSH into the server. I’m also able to start the server successfully. I have server.js
, script.js
, index.html
and styles.css
all in the same directory (the default one, which is public_html
). The problem is that making a GET request to /getRequest
or even the root /, doesn’t work, even if it does locally when accessing localhost:3000
. I couldn’t get all of these working together when accessing my site at example.com
, so I tried to create a more simple server. I still can’t get this to work. Same problem happens where it works locally but not online. When trying online, the request to both the root and example.com/getRequest
aren’t found. The /getRequest
shows a 404 when inspecting in browser, and the request to the root returns the default ‘Coming Soon’ page. Why is the server unable to respond to requests? Is this some misconfiguration I’ve done through GoDaddy?
server.js is:
const express = require('express');
const app = express();
app.use(cors());
//app.get('/getRequest', (req, res) => {
app.get('/', (req, res) => {
const variableString = "Hello, world!";
res.json({ variableString });
});
app.listen(port, () => {
console.log(`Server is running at http://${hostname}:${port}`);
});
and script.js is (with ‘host’ and ‘port’ variables coming from the output from the server when it first starts):
//fetch('{myHost}:{myPort}/getRequest')
fetch('{myHost}:{myPort}')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log(data.message);
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});