Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Jan 14, 2016
2 parents e42a1fa + cc69f51 commit b80384c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ webappengine({
{
type: 'server',
route: '/',
// An absolute path is recommended to use
server: path.resolve(__dirname, 'app/app')
server: function(options) {
var route = options.route;
}
}
]
});
Expand All @@ -67,7 +68,6 @@ var options = {
{
type: 'static', // [static|server]
route: '/',
//server: path.resolve(__dirname, 'app/app'), // for the server type
directory: path.resolve(__dirname, 'web') // for the static type
}
]
Expand Down
29 changes: 21 additions & 8 deletions app/app.multihost.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,28 @@ module.exports = function() {
}

try {
// Modules are cached after the first time they are loaded.
// The cached module must be invalidated to ensure data-independences in a multi-host environment.
var server_path = path.resolve(options.server);
if (require.cache[server_path]) {
delete require.cache[server_path];
var server = options.server;

if (typeof server === 'string') {
// Modules are cached after the first time they are loaded.
// The cached module must be invalidated to ensure data-independences in a multi-host environment.
var server_path = path.resolve(options.server);
if (require.cache[server_path]) {
delete require.cache[server_path];
}

server = require(server_path);

// Ready for ES6
if (typeof server === 'object') {
server = server.default;
}
}

var server = require(server_path);
if (typeof server !== 'function') {
log.error('The multi-host server does not exist:', JSON.stringify(options, null, 4));
return;
}

app.use(middleware.multihost({
hosts: options.hosts,
Expand All @@ -98,12 +112,11 @@ module.exports = function() {
}));
}
catch (e) {
log.error(e);
console.log(e.stack);
log.error('The multi-host server does not exist:', JSON.stringify(options, null, 4));
return;
}


log.info('Attached a multi-host server:', JSON.stringify(options, null, 4));
});
}(app));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webappengine",
"version": "0.6.3",
"version": "0.7.0",
"description": "A web application platform that can host multiple web apps running with Node.js.",
"homepage": "https://github.com/cheton/webappengine",
"author": "Cheton Wu <cheton@gmail.com>",
Expand Down

0 comments on commit b80384c

Please sign in to comment.