I'm trying to host multiple node services in one application. So I'm using express, vhost and connect to route them by following this answer: Combine multiple node js services
And I have my app.js snippet:
var path = require('path');
var AWS = require('aws-sdk');
var util = require('util');
var vhost = require('vhost');
var connect = require('connect');
var async = require('async');
var serveStatic = require('serve-static');
var port = process.env.PORT || 3000,
http = require('http');
var log4js = require('log4js');
var moment = require('moment');
var express = require('express'),
main = express();
main.use(vhost('*.site1.com',require('./')));
I got the error when node tried to execute the last line.
This is how I get the request in ./index.js:
var myservice = require('./myService').handler;
myservice({
eventjson...
...
},function(err) {
console.log('Some error!');
});
var app = express();
app.get('/', function(req,res){
res.send('Home Page');
});
And my app hierarchy is:
myservice
|__app.js
|__index.js
|__myservice.js
|__package.json
I think the problem comes with require('./')
, but how should I change it?