I am using the example setup from the https://www.npmjs.com/package/express-subdomain package. However, when I try api.localhost:3000 in a browser it throws an error: "Cannot GET /"
How can I get api.localhost:3000 running? I would consider other solutions, not just ones using express-subdomain
as long as you don't have to type in the fqdn in the setup.
app.js:
var subdomain = require('express-subdomain');
var express = require('express');
var app = express();
// *** Code examples below go here! ***
var router = express.Router();
//api specific routes
router.get('/', function(req, res) {
res.send('Welcome to our API!');
});
router.get('/users', function(req, res) {
res.json([
{ name: "Brian" }
]);
});
app.use(subdomain('api', router));
app.listen(3000);
package.json:
{
"name": "auth_manager",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.3",
"express-subdomain": "^1.0.5"
}
}