0

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?

Community
  • 1
  • 1
RandomEli
  • 1,527
  • 5
  • 30
  • 53
  • And what is `require('./')` supposed to require? The vhost middleware expects a function as the second argument, that gets the arguments `req, res, next` just as a route. – adeneo Jun 07 '16 at 23:10
  • To be clearer, try something like **https://jsfiddle.net/by1x34e6/**, and see what you get. – adeneo Jun 07 '16 at 23:11
  • `require('./')` supposed to require index.js under ./ path. – RandomEli Jun 08 '16 at 01:10

0 Answers0