Skip to content
This repository has been archived by the owner on Jan 16, 2018. It is now read-only.

Allow testing on devices other than localhost over the network (such as cell phones and tablets) #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions config/SimpleRenderer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
var fs = require("fs");
var path = require("path");
var html = fs.readFileSync(path.resolve(__dirname, "../app/simple.html"), "utf-8");
var URL = require("url");

function SimpleRenderer(options) {
this.html = html.replace("SCRIPT_URL", options.scriptUrl);
this.options = options;
this.html = html;
}

SimpleRenderer.prototype.render = function(_path, _readItems, callback) {
callback(null, this.html);
SimpleRenderer.prototype.render = function(req, _readItems, callback) {
urlObj = URL.parse(this.options.scriptUrl);
urlObj.host = null;
urlObj.hostname = req.hostname;
callback(null, this.html.replace("SCRIPT_URL", URL.format(urlObj)));
};

module.exports = SimpleRenderer;
module.exports = SimpleRenderer;
6 changes: 3 additions & 3 deletions config/mainPrerenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export default class MainRenderer {
.replace("COMMONS_URL", options.commonsUrl);
}

render(path, readItems, callback) {
render(req, readItems, callback) {
var stores = createStoresForPrerender(storesDescriptions, readItems);
this.prerenderer.getContent(path, stores, (err, content, data) => {
this.prerenderer.getContent(req.path, stores, (err, content, data) => {
if(err) return callback(err);
var page = this.html
.replace("DATA", JSON.stringify(data))
.replace("CONTENT", content);
callback(null, page);
});
}
}
}
4 changes: 2 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = function(options) {
// application
app.get("/*", function(req, res) {
renderer.render(
req.path,
req,
createPrerenderApi(req),
function(err, html) {
if(err) {
Expand All @@ -70,4 +70,4 @@ module.exports = function(options) {
app.listen(port, function() {
console.log("Server listening on port " + port);
});
};
};
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "app/app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev-server": "webpack-dev-server --config webpack-dev-server.config.js --progress --colors --port 2992 --inline",
"hot-dev-server": "webpack-dev-server --config webpack-hot-dev-server.config.js --hot --progress --colors --port 2992 --inline",
"dev-server": "webpack-dev-server --host 0.0.0.0 --config webpack-dev-server.config.js --progress --colors --port 2992 --inline",
"hot-dev-server": "webpack-dev-server --host 0.0.0.0 --config webpack-hot-dev-server.config.js --hot --progress --colors --port 2992 --inline",
"build": "webpack --config webpack-production.config.js --progress --profile --colors",
"start-dev": "node lib/server-development",
"start": "node lib/server-production"
Expand Down Expand Up @@ -45,11 +45,11 @@
"url-loader": "^0.5.5",
"uuid": "^2.0.1",
"webpack": "^1.8.5",
"webpack-dev-server": "^1.4.7"
"webpack-dev-server": "^1.11.0"
},
"devDependencies": {
"babel-eslint": "^3.0.1",
"eslint": "^0.22.0",
"eslint-plugin-react": "^2.2.0"
}
}
}