1

I created a test app for using subdomains. it is not woking. when get api.localhost:3000 it shows localhost:3000... index.js:

var subdomain = require('express-subdomain');
var express = require('express');
var app = express();
var router = express.Router();

app.get("/", (req, res)=>{
    res.send("silav")
})
//routers 
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)

and lines of edited etc/hosts:

127.0.0.1       localhost
127.0.0.1       api.localhost
::1             localhost

thanks

bahoz99
  • 121
  • 1
  • 6

0 Answers0