I am trying to implement a simple nodejs server with Express routing on A2 Shared Hosting service (once I get this working I can deploy a more complex app I have been working on).
The root returns a response (API Running) but I get a 503 error on any other routes I try setting up. I have gone through many postings but none seem to address my exact problem. The hosting service has an article suggesting using dynamic post assignment (which I have implemented).
If the root works but other routing doesn't, could this be something to do with EXPRESS (but again that works fine on localhost)?
The server.js file looks like this:
const express = require('express');
const snow = require('./routes/api/snow');
const app = express();
// Middle ware init
app.use(express.json({ extended: false }));
app.get('/snowshoe/', (req, res) => res.send('API Running'));
// Define routes
app.use('/snowshoe/api/snow', snow);
const server = app.listen(0, () => {
console.log('Example app listening at http://localhost:', server.address().port);
});
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that!")
})
and the /snowshoe/api/snow.js looks like this:
const express = require('express');
const router = express.Router();
router.get('/', (req, res) => res.send('Snow plow required'));
module.exports = router;
Perhaps something with the Express routing?
package.json
{
"name": "snowshoe",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.2"
}
}