Skip to content

Commit

Permalink
Merge pull request sbstjn#26 from musterknabe/feature/host-support
Browse files Browse the repository at this point in the history
Removed hardcoded localhost reference
  • Loading branch information
sbstjn committed Aug 19, 2014
2 parents c396ff0 + ec1ca99 commit 9fef2c5
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion public/scripts/app.motor.js
Expand Up @@ -21,7 +21,7 @@ require(["jquery", pv + "dropdown.js", pv + "prettify.js", pl + 'Noduino.js', pl
$('#connect').click(function(e) {
e.preventDefault();
if (!Noduino || !Noduino.connected) {
Noduino = new NoduinoObj({debug: true, host: 'http://localhost:8090', logger: {container: '#connection-log'}}, Connector, Logger);
Noduino = new NoduinoObj({debug: true, host: 'http://' + location.hostname + ':8090', logger: {container: '#connection-log'}}, Connector, Logger);
Noduino.connect(function(err, board) {
$('#connection-status .alert').addClass('hide');
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion public/scripts/app.walkLED.js
Expand Up @@ -94,7 +94,7 @@ require(["jquery", pv + "dropdown.js", pv + "prettify.js", pl + 'Noduino.js', pl
e.preventDefault();

if (!Noduino || !Noduino.connected) {
Noduino = new NoduinoObj({debug: true, host: 'http://localhost:8090', logger: {container: '#connection-log'}}, Connector, Logger);
Noduino = new NoduinoObj({debug: true, host: 'http://' + location.hostname + ':8090', logger: {container: '#connection-log'}}, Connector, Logger);
Noduino.connect(function(err, board) {
$('#connection-status .alert').addClass('hide');
if (err) {
Expand Down
4 changes: 2 additions & 2 deletions public/scripts/example-1.js
Expand Up @@ -5,7 +5,7 @@ define(function() {

Example.handle = function() {
require(['scripts/libs/Noduino.js', 'scripts/libs/Noduino.Socket.js', 'scripts/libs/Logger.js'], function(NoduinoObj, Connector, Logger) {
var Noduino = new NoduinoObj({debug: false, host: 'http://localhost:8090'}, Connector, Logger);
var Noduino = new NoduinoObj({debug: false, host: 'http://' + location.hostname + ':8090'}, Connector, Logger);
Noduino.connect(function(err, board) {
$('#e1-exampleConnection .alert').addClass('hide');
if (err) {
Expand All @@ -17,4 +17,4 @@ define(function() {
};

return Example;
});
});
4 changes: 2 additions & 2 deletions public/scripts/example-2.js
Expand Up @@ -7,7 +7,7 @@ define(function() {
Example2.handle = function() {
var that = this;
require(['scripts/libs/Noduino.js', 'scripts/libs/Noduino.Socket.js', 'scripts/libs/Logger.js'], function(NoduinoObj, Connector, Logger) {
var Noduino = new NoduinoObj({debug: false, host: 'http://localhost:8090'}, Connector, Logger);
var Noduino = new NoduinoObj({debug: false, host: 'http://' + location.hostname + ':8090'}, Connector, Logger);
Noduino.connect(function(err, board) {
$('#e2-exampleConnection .alert').addClass('hide');
if (err) {
Expand Down Expand Up @@ -49,4 +49,4 @@ define(function() {
};

return Example2;
});
});
2 changes: 1 addition & 1 deletion public/scripts/example-3.js
Expand Up @@ -6,7 +6,7 @@ define(function() {
Example3.handle = function() {

require(['scripts/libs/Noduino.js', 'scripts/libs/Noduino.Socket.js', 'scripts/libs/Logger.js'], function(NoduinoObj, Connector, Logger) {
var Noduino = new NoduinoObj({debug: false, host: 'http://localhost:8090'}, Connector, Logger);
var Noduino = new NoduinoObj({debug: false, host: 'http://' + location.hostname + ':8090'}, Connector, Logger);
Noduino.connect(function(err, board) {
$('#e3-exampleConnection .alert').addClass('hide');
if (err) {
Expand Down
18 changes: 12 additions & 6 deletions srv.app.js
Expand Up @@ -9,7 +9,13 @@
*/

define(['kickstart', 'module', 'path', 'fs'], function (kickstart, module, path, fs) {
var kickstart = kickstart.withConfig({'name': 'localhost', 'port': 8080, 'path': './'});
var args = process.argv.splice(2);

var hostname = args[0] || 'localhost';
var port = args[1] || 8080;
var host = hostname + ':' + port;

var kickstart = kickstart.withConfig({'name': hostname, 'port': port, 'path': './'});
var srv = kickstart.srv();

/**
Expand All @@ -29,29 +35,29 @@ define(['kickstart', 'module', 'path', 'fs'], function (kickstart, module, path,
* Catch request for serving home page
*/
srv.all('/', function(req, res) {
res.render('home', {jsApp: 'main', active: 'home', title: 'noduino', 'examples': examples});
res.render('home', {hostname: hostname, jsApp: 'main', active: 'home', title: 'noduino', 'examples': examples});
});

/**
* Catch request for Getting Started page
*/
srv.all('/getting-started.html', function(req, res) {
res.render('getting-started', {jsApp: 'none', active: 'getting-started', title: 'noduino', 'examples': examples});
res.render('getting-started', {hostname: hostname, jsApp: 'none', active: 'getting-started', title: 'noduino', 'examples': examples});
});

/**
* Catch request for serving walkLED example page
*/
srv.all('/example-walkLED.html', function(req, res) {
res.render('example-walkLED', {jsApp: 'walkLED', active: 'examples', title: 'noduino', 'examples': examples});
res.render('example-walkLED', {hostname: hostname, jsApp: 'walkLED', active: 'examples', title: 'noduino', 'examples': examples});
});

/**
* Catch request for serving motor example
*/
srv.all('/example-motor.html', function(req, res) {
res.render('example-motor', {jsApp: 'motor', active: 'examples', title: 'noduino', 'examples': examples});
res.render('example-motor', {hostname: hostname, jsApp: 'motor', active: 'examples', title: 'noduino', 'examples': examples});
});

return {'kickstart': kickstart, 'srv': srv};
});
});
4 changes: 4 additions & 0 deletions views/getting-started.jade
Expand Up @@ -16,6 +16,10 @@
img(src="images/getting-started/2.png")
h2 Start Noduino and have fun!
p Start Noduino's WebSocket Server with <code>node srv.web.js</code>, connect your prepared Arduino, open <a href="http://localhost:8080">http://localhost:8080</a> with your browser and have fun. If you run into any problems during the provided examples please restart <code>srv.web.js</code>, there are some known issues on getting a connection if your browser has already connected or you are using multiple tabs. Keep in mind that Noduino is highly alpha software…
p If you want to access Noduino from a different computer or run it on a server (i.e. Raspberry Pi) you need to set the hostname and port like this:
p <code>node srv.web.js [hostname] [port]</code>
p For example:
p <code>node srv.web.js 192.168.0.100 8081</code>
br
.hero-unit
img(src="images/getting-started/3.png")
Expand Down
2 changes: 1 addition & 1 deletion views/layout.jade
Expand Up @@ -6,7 +6,7 @@ html(lang="en")
link(rel="stylesheet", href="styles/prettify.css")
link(rel="stylesheet", href="styles/init.css")
script(data-main="scripts/app." + jsApp, type="text/javascript", src="scripts/vendor/require-jquery.js")
script(type="text/javascript", src="http://localhost:8090/socket.io/socket.io.js")
script(type="text/javascript", src="//" + hostname + ":8090/socket.io/socket.io.js")
body
.navbar.navbar-fixed-top(style="z-index: 4;position:absolute;")
.navbar-inner
Expand Down

0 comments on commit 9fef2c5

Please sign in to comment.