Tuesday, November 5, 2013

Proxy Nodejitsu drone witth nginx

When developing an Angluar application, I needed to make requests to remove servers, and encountered the "Access-Control-Allow-Origin" problem. To overcome this, I decided to proxy the remote server using nginx. Since a remote server was a nodejitsu drone, I needed to modify my nginx configuration a little further than normal:
upstream api {
# server 127.0.0.1:3030; # Standard proxy_pass server to locally running server
server librecms-api.jit.su:80; # proxy_pass server to remote nodejitsu drone.
}
server {
listen 80;
server_name localhost;
root /var/www/librecms/src/angular/app;
underscores_in_headers on;
location /api/ {
##### proxy_pass configuration for all upstream servers
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://api/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
#### NOTE THIS IS SPECIFIC FOR NOTEJITSU DRONES.
#### Must set Host header to domain of nodejitsu drone.
proxy_set_header Host librecms-api.jit.su;
}
location / {
# Application specific
index index.html;
try_files $uri $uri/ /index.html =404;
}
}
view raw gistfile1.txt hosted with ❤ by GitHub
Note the proxy_set_header Host line. This is needed because nodejitsu proxies their drones according to the Host header (docs).

Wednesday, October 30, 2013

Unit testing state transitions with ui-router and karma/jasmine

Testing ui-router state transitions with karma/jasmine is straightforward. The unit test:
'use strict';
describe('Controller: CourseCtrl', function () {
// load the controller's module
beforeEach(module('myApp'));
// load controller widgets/views/partials
var views = [
'views/course.html',
'views/main.html'
];
views.forEach(function(view) {
beforeEach(module(view));
});
var CourseCtrl,
scope;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
CourseCtrl = $controller('CourseCtrl', {
$scope: scope
});
}));
it('should should transition to main.course', inject(function ($state, $rootScope) {
$state.transitionTo('main.course');
$rootScope.$apply();
expect($state.current.name).toBe('main.course');
}));
});
view raw gistfile1.js hosted with ❤ by GitHub
And karma configuration:
module.exports = function(config) {
'use strict';
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/scripts/*.js',
'app/scripts/**/*.js',
'app/views/**/*.html',
'test/spec/**/*.js'
],
exclude: [],
port: 8080,
preprocessors: {
'app/views/**/*.html': 'html2js'
},
ngHtml2JsPreprocessor: {
stripPrefix: 'app/'
},
logLevel: config.LOG_INFO,
autoWatch: false,
// - IE (only Windows)
browsers: ['PhantomJS'],
singleRun: false
});
};
view raw gistfile1.txt hosted with ❤ by GitHub
Note the html preprocessor and inclusion of the views in the "files" array.

Thursday, April 11, 2013

Extended desktop using XFCE

In the XFCE display settings manager, if you see your screen but instead of extending the desktop it clones the desktop on both displays.




To enable this. use xrandr
You should see something like this

LVDS1 connected 1366x768+0+0 (normal left inverted right x axis y axis) 310mm x 174mm

blahblah

HDMI1 connected 1280x720+1366+0 (normal left inverted right x axis y axis) 16mm x 9mm

To extend the desktop and use the HDMI connected monitor on the right side, do this:
➜  ~  xrandr --output HDMI1 --right-of LVDS1