ember-fastboot-server
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -20,2 +20,3 @@ var fs = require('fs'); | ||
var moduleWhitelist = options.moduleWhitelist; | ||
this._hostWhitelist = options.hostWhitelist; | ||
@@ -75,3 +76,3 @@ debug("app created; app=%s; vendor=%s", appFilePath, vendorFilePath); | ||
return this.buildApp() | ||
.then(registerFastBootInfo(req, res)) | ||
.then(registerFastBootInfo(req, res, this._hostWhitelist)) | ||
.then(function(instance) { | ||
@@ -105,5 +106,5 @@ return instance.boot(bootOptions); | ||
*/ | ||
function registerFastBootInfo(req, res) { | ||
function registerFastBootInfo(req, res, hostWhitelist) { | ||
return function(instance) { | ||
var info = new FastBootInfo(req, res); | ||
var info = new FastBootInfo(req, res, hostWhitelist); | ||
info.register(instance); | ||
@@ -110,0 +111,0 @@ |
@@ -8,3 +8,3 @@ var cookie = require('cookie'); | ||
*/ | ||
function FastBootInfo(request, response) { | ||
function FastBootInfo(request, response, hostWhitelist) { | ||
this.request = request; | ||
@@ -15,2 +15,3 @@ this.response = response; | ||
this.headers = request.headers; | ||
this.hostWhitelist = hostWhitelist; | ||
} | ||
@@ -35,2 +36,28 @@ | ||
FastBootInfo.prototype.host = function() { | ||
if (!this.hostWhitelist) { | ||
throw new Error('You must provide a hostWhitelist to retrieve the host'); | ||
} | ||
var host = this.request.headers.host; | ||
var matchFound = this.hostWhitelist.reduce(function(previous, currentEntry) { | ||
if (currentEntry[0] === '/' && | ||
currentEntry.slice(-1) === '/') { | ||
// RegExp as string | ||
var regexp = new RegExp(currentEntry.slice(1, -1)); | ||
return previous || regexp.test(host); | ||
} else { | ||
return previous || currentEntry === host; | ||
} | ||
}, false); | ||
if (!matchFound) { | ||
throw new Error('The host header did not match a hostWhitelist entry'); | ||
} | ||
return this.request.protocol + '://' + host; | ||
}; | ||
/* | ||
@@ -37,0 +64,0 @@ * Registers this FastBootInfo instance in the registry of an Ember |
@@ -1,10 +0,25 @@ | ||
var chalk = require('chalk'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var chalk = require('chalk'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var util = require('util'); | ||
var EmberApp = require('./ember-app'); | ||
var debug = require('debug')('ember-cli-fastboot:server'); | ||
var debug = require('debug')('ember-cli-fastboot:server'); | ||
function FastBootServer(options) { | ||
options = options || {}; | ||
var distPath = options.distPath; | ||
if (!distPath) { | ||
throw new Error('You must instantiate FastBootServer with a distPath ' + | ||
'option that contains a path to a fastboot-dist directory ' + | ||
'produced by running ember fastboot:build in your Ember app:' + | ||
'\n\n' + | ||
'new FastBootServer({\n' + | ||
' distPath: \'path/to/fastboot-dist\'\n' + | ||
'});'); | ||
} | ||
var config = readPackageJSON(distPath); | ||
// Stubs out the `ui` object for printing to the terminal used | ||
@@ -22,3 +37,4 @@ // by Ember CLI addons. | ||
vendorFile: config.vendorFile, | ||
moduleWhitelist: config.moduleWhitelist | ||
moduleWhitelist: config.moduleWhitelist, | ||
hostWhitelist: config.hostWhitelist | ||
}); | ||
@@ -107,20 +123,29 @@ | ||
var pkgPath = path.join(distPath, 'package.json'); | ||
var file; | ||
try { | ||
var file = fs.readFileSync(pkgPath); | ||
file = fs.readFileSync(pkgPath); | ||
} catch (e) { | ||
throw new Error(util.format("Couldn't find %s. You may need to update your version of ember-cli-fastboot.", pkgPath)); | ||
} | ||
var pkg = JSON.parse(file); | ||
var manifest = pkg.fastboot.manifest; | ||
var manifest; | ||
var pkg; | ||
return { | ||
appFile: path.join(distPath, manifest.appFile), | ||
vendorFile: path.join(distPath, manifest.vendorFile), | ||
htmlFile: path.join(distPath, manifest.htmlFile), | ||
moduleWhitelist: pkg.fastboot.moduleWhitelist | ||
}; | ||
try { | ||
pkg = JSON.parse(file); | ||
manifest = pkg.fastboot.manifest; | ||
} catch (e) { | ||
console.log("Couldn't find %s. You may need to update your version of ember-cli-fastboot.", pkgPath); | ||
throw new Error(util.format("%s was malformed or did not contain a manifest. Ensure that you have a compatible version of ember-cli-fastboot.", pkgPath)); | ||
} | ||
return { | ||
appFile: path.join(distPath, manifest.appFile), | ||
vendorFile: path.join(distPath, manifest.vendorFile), | ||
htmlFile: path.join(distPath, manifest.htmlFile), | ||
moduleWhitelist: pkg.fastboot.moduleWhitelist, | ||
hostWhitelist: pkg.fastboot.hostWhitelist | ||
}; | ||
} | ||
module.exports = FastBootServer; |
{ | ||
"name": "ember-fastboot-server", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Production server for running Ember applications using FastBoot", | ||
"main": "./lib/server", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha" | ||
}, | ||
@@ -34,7 +34,13 @@ "repository": { | ||
"minimist": "^1.2.0", | ||
"najax": "^0.3.2", | ||
"najax": "^0.4.0", | ||
"rsvp": "^3.0.16", | ||
"simple-dom": "^0.2.7", | ||
"source-map-support": "^0.4.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"chai-as-promised": "^5.2.0", | ||
"mocha": "^2.4.5", | ||
"request-promise": "^2.0.1" | ||
} | ||
} |
# Ember FastBoot Server | ||
[![Build Status](https://travis-ci.org/ember-fastboot/ember-fastboot-server.svg?branch=master)](https://travis-ci.org/ember-fastboot/ember-fastboot-server) | ||
The Ember FastBoot Server is used to render Ember.js applications on the | ||
@@ -4,0 +6,0 @@ server and deliver them to clients over HTTP. This server is meant to be |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
5976049
26
71435
1
47
4
3
+ Addednajax@0.4.0(transitive)
- Removednajax@0.3.2(transitive)
Updatednajax@^0.4.0