Firstly, found a couple of similar question on here but no duplicates, I think my situation is slightly different.
Trying to get a website and associated API working on Express using vhost for subdomians.
Here is my folder structure
/api
api.js
/server
website.js
server.js
My server.js
const vhost = require('vhost');
const express = require('express');
const app = express();
app.use(vhost('localhost', require('./server/website.js').app));
app.use(vhost('api.localhost', require('./api/api.js').app));
app.listen(1337, () => {});
My api.js
const express = require('express');
const app = express();
app.get('/', function(req, res){
res.send({ hello: 'world' });
});
module.exports = app;
Initially my path to api.js was wrong and I got a not found error so now I know my path is right but now I get the error "Typeerror: argument handle is required" whatever I do.
Any help would really be appreciated.
Your exporting the app already. So it is not necessary to add .app to the end of your require.
It should be:
Hope that helps.