I am trying to connect to an API that I have up and running on my local machine but I can't access on my production server.
It's running on node.js with mongoose and I have set up the server to listen on port 3000.
When I test in postman: http://178.128.37.170:3000/
I get the following response:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<>Cannot GET /</>
</body>
</html>
I have created a 'Hello world' response in the router: app.get('/', (req, res) => res.send('Hello World!'))
I am not sure where this is getting blocked, if it is a port, firewall or IP issue or something else. I have disabled both Apache and SSL in case they were interfering.
Here is my server.js file:
var express = require('express'),
cors = require('cors'),
app = express(),
port = process.env.PORT || 3000,
mongoose = require('mongoose'),
Supporter = require('./api/models/todoListModel'), //created model loading here
bodyParser = require('body-parser'),
helmet = require('helmet');
// Test SSL connection
var MongoClient = require('mongodb').MongoClient;
// mongoose instance connection url connection
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost/Tododb'); // was tododb
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(helmet());
app.use(cors());
app.get('/task/', function (req, res, next) {
res.json({msg: 'This is CORS-enabled for all origins!'})
})
var routes = require('./api/routes/todoListRoutes');
routes(app); //register the route
app.listen(port);
console.log('Supporter RESTful API server started on: ' + port);
What should I try next?
app.get('/', ...)does not appear in yourserver.jsCan you access/taskfrom Postman? - SamuelSupporter = require('./api/models/todoListModel'), //created model loading herewas incorrect so I changed that and I can now get a response from /task but I am still getting no response from /tasks/1 which is where my routes are pointing. - PhilipAbbott/and now it'stask/1- Samuel