Skip to content

Instantly share code, notes, and snippets.

@cmcculloh
Last active May 11, 2021 19:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmcculloh/6718942 to your computer and use it in GitHub Desktop.
Save cmcculloh/6718942 to your computer and use it in GitHub Desktop.
Proxying a request through node from front end to different server
//public/javascripts/app/app.js
define(function (require) {
//require dependancies
var Marionette = require('backbone.marionette');
var Backbone = require('backbone');
var $ = require('jquery');
// Override renderer to use pre-compiled templates
Marionette.Renderer.render = function render(template, data) {
return template(data);
};
// Create, configure, and return application object
var app = new Marionette.Application();
app.addRegions({
mainRegion: '#main'
});
app.addInitializer(function (options) {
this.router = options.router;
this.models = new Backbone.Model();
this.views = new Backbone.Model();
});
app.on('initialize:after', function () {
$(function () {
Backbone.history.start();
});
});
return app;
});
//public/javascripts/app/controller.js
define(function (require) {
var config = require('config');
var app = require('./app');
var Backbone = require('backbone');
var Marionette = require('backbone.marionette');
var BaseCollection = require('models/base-collection');
var Application = Backbone.Model.extend({url: function url(){
return.config.rest + 'v1/applications/{id}';
});
var Applications = Backbone.Collection.extend({model: Application,url: function url() {
return config.rest + 'v1/applications';
}});
app.addInitializer(function () {
this.models.set({
applications: new Applications()
});
});
var controller = {
showApps: function showMongoAppCenter(reloadDeveloper) {
app.models.get('applications').fetch({
success: function success() {
console.log('fetch apps', arguments);
},
error: function error() {
console.log('error', arguments);
}
});
}
};
return controller;
});
//config/default.js
module.exports = {
restProxy: {
host: "www.ex.com",
port: 443,
https: true
},
restServerURI: 'https://www.ex.com/'
};
//lib/myconfig.js
var config = require('config');
module.exports = {
clientConfig: function (session) {
return {
rest: config.rest,
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment