Add in proxy to track changes api

This commit is contained in:
James Allen 2014-03-05 16:31:52 +00:00
parent f781001280
commit 0468cbc300
3 changed files with 63 additions and 0 deletions

View file

@ -0,0 +1,13 @@
logger = require "logger-sharelatex"
request = require "request"
settings = require "settings-sharelatex"
module.exports = TrackChangesController =
proxyToTrackChangesApi: (req, res, next = (error) ->) ->
url = settings.apis.trackchanges.url + req.url
logger.log url: url, "proxying to track-changes api"
getReq = request.get(url)
getReq.pipe(res)
getReq.on "error", (error) ->
logger.error err: error, "track-changes API error"
next(error)

View file

@ -32,6 +32,7 @@ CompileController = require("./Features/Compile/CompileController")
HealthCheckController = require("./Features/HealthCheck/HealthCheckController")
ProjectDownloadsController = require "./Features/Downloads/ProjectDownloadsController"
FileStoreController = require("./Features/FileStore/FileStoreController")
TrackChangesController = require("./Features/TrackChanges/TrackChangesController")
logger = require("logger-sharelatex")
httpAuth = require('express').basicAuth (user, pass)->
@ -122,6 +123,9 @@ module.exports = class Router
app.get '/Project/:Project_id/version', SecutiryManager.requestCanAccessProject, versioningController.listVersions
app.get '/Project/:Project_id/version/:Version_id', SecutiryManager.requestCanAccessProject, versioningController.getVersion
app.get "/project/:Project_id/doc/:doc_id/updates", SecutiryManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi
app.get "/project/:Project_id/doc/:doc_id/diff", SecutiryManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi
app.post '/project/:project_id/leave', AuthenticationController.requireLogin(), CollaboratorsController.removeSelfFromProject
app.get '/project/:Project_id/collaborators', SecutiryManager.requestCanAccessProject(allow_auth_token: true), CollaboratorsController.getCollaborators

View file

@ -0,0 +1,46 @@
chai = require('chai')
chai.should()
sinon = require("sinon")
modulePath = "../../../../app/js/Features/TrackChanges/TrackChangesController"
SandboxedModule = require('sandboxed-module')
describe "TrackChangesController", ->
beforeEach ->
@TrackChangesController = SandboxedModule.require modulePath, requires:
"request" : @request = {}
"settings-sharelatex": @settings = {}
"logger-sharelatex": @logger = {log: sinon.stub(), error: sinon.stub()}
describe "proxyToTrackChangesApi", ->
beforeEach ->
@req = { url: "/mock/url" }
@res = "mock-res"
@next = sinon.stub()
@settings.apis =
trackchanges:
url: "http://trackchanges.example.com"
@proxy =
events: {}
pipe: sinon.stub()
on: (event, handler) -> @events[event] = handler
@request.get = sinon.stub().returns @proxy
@TrackChangesController.proxyToTrackChangesApi @req, @res, @next
describe "successfully", ->
it "should call the track changes api", ->
@request.get
.calledWith("#{@settings.apis.trackchanges.url}#{@req.url}")
.should.equal true
it "should pipe the response to the client", ->
@proxy.pipe
.calledWith(@res)
.should.equal true
describe "with an error", ->
beforeEach ->
@proxy.events["error"].call(@proxy, @error = new Error("oops"))
it "should pass the error up the call chain", ->
@next.calledWith(@error).should.equal true