I am trying to use Express as my server in MEAN stack on AWS. However I've ran into a issue trying to setup subdomains. I have my main domain name domain.com and id like to have app.domain.com.. However I've tried everything I've found online to write the functionality into the server.js file and nothing works. How can I easily accomplish this to make the second function instead of loading on Port 8000 load up at my app.domain.com sub domain? Thanks in advance!
var express = require('express');
// Main Website
var web = express();
web.get('/', function (req, res){
res.sendFile('/web/index.html', { root: '.' })
});
var port = 9000;
web.listen(port);
console.log('Web Listening on port', port);
//Main Application
var app = express();
app.get('/', function (req, res){
res.sendFile('/app/index.html', { root: '.' })
});
var port = 8000;
app.listen(port);
console.log('Web Listening on port', port);
Update:
I tried using Vhost here but it loads the same thing for both the main domain and the sub domain and so it does not work. here is the code I used:
var express = require('express');
var connect = require('connect');
var http = require('http');
var vhost = require('vhost');
// Main Website
var web = express();
web.get('/', function (req, res){
res.sendFile('/web/index.html', { root: '.' })
});
var port = 9000;
web.listen(port);
console.log('Web Listening on port', port);
//Main Application
var app = connect()
app.use(vhost('app.domain.com', function (req, res) {
res.sendFile('/app/index.html', { root: '.' })
httpServer.emit('request', req, res)
}))
app.listen(8000)
I don't really need these to be on separate ports that was just something I was trying originally. But either way does not work still..