Last active
May 11, 2021 19:25
-
-
Save cmcculloh/6718942 to your computer and use it in GitHub Desktop.
Proxying a request through node from front end to different server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//config/default.js | |
module.exports = { | |
restProxy: { | |
host: "www.ex.com", | |
port: 443, | |
https: true | |
}, | |
restServerURI: 'https://www.ex.com/' | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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