university site renders via prozy ok

This commit is contained in:
Henry Oswald 2014-10-08 16:07:44 +01:00
parent 8789a4bde1
commit c2c29bb282
6 changed files with 63 additions and 1 deletions

View file

@ -12,6 +12,8 @@ module.exports = BlogController =
url = req.url?.toLowerCase() url = req.url?.toLowerCase()
blogUrl = "#{settings.apis.blog.url}#{url}" blogUrl = "#{settings.apis.blog.url}#{url}"
extensionsToProxy = [".png", ".xml", ".jpeg", ".json", ".zip", ".eps"]
shouldProxy = _.find extensionsToProxy, (extension)-> shouldProxy = _.find extensionsToProxy, (extension)->
url.indexOf(extension) != -1 url.indexOf(extension) != -1

View file

@ -0,0 +1,12 @@
extensionsToProxy = [".png", ".xml", ".jpeg", ".json", ".zip", ".eps", ".gif", ".jpg"]
_ = require("underscore")
module.exports =
shouldProxy: (url)->
shouldProxy = _.find extensionsToProxy, (extension)->
url.indexOf(extension) != -1
return shouldProxy

View file

@ -1,4 +1,6 @@
HomeController = require('./HomeController') HomeController = require('./HomeController')
UniversityController = require("./UniversityController")
module.exports = module.exports =
apply: (app) -> apply: (app) ->
@ -13,3 +15,6 @@ module.exports =
app.get '/style', HomeController.externalPage("style_guide", "Style Guide") app.get '/style', HomeController.externalPage("style_guide", "Style Guide")
app.get '/dropbox', HomeController.externalPage("dropbox", "Dropbox and ShareLaTeX") app.get '/dropbox', HomeController.externalPage("dropbox", "Dropbox and ShareLaTeX")
app.get '/university', UniversityController.getIndexPage
app.get '/university/*', UniversityController.getPage

View file

@ -0,0 +1,34 @@
request = require("request")
settings = require("settings-sharelatex")
logger = require("logger-sharelatex")
_ = require("underscore")
ErrorController = require "../Errors/ErrorController"
StaticPageHelpers = require("./StaticPageHelpers")
module.exports = UniversityController =
getPage: (req, res, next)->
url = req.url?.toLowerCase()
universityUrl = "#{settings.apis.university.url}#{url}"
console.log universityUrl
if StaticPageHelpers.shouldProxy(url)
return UniversityController._directProxy universityUrl, res
logger.log url:url, "proxying request to university api"
request.get universityUrl, (err, r, data)->
if r?.statusCode == 404
return ErrorController.notFound(req, res, next)
data = data.trim()
try
data = JSON.parse(data)
catch err
logger.err err:err, data:data, "error parsing data from data"
res.render "university/university_holder", data
getIndexPage: (req, res)->
req.url = "/university/index.html"
UniversityController.getPage req, res
_directProxy: (originUrl, res)->
request.get(originUrl).pipe res

View file

@ -0,0 +1,6 @@
extends ../layout
block content
.content.content-alt
.blog
| !{content}

View file

@ -82,6 +82,8 @@ module.exports =
internal_url: "http://localhost:3010" internal_url: "http://localhost:3010"
blog: blog:
port: 3008 port: 3008
university:
url: "http://localhost:3011"
filestore: filestore:
url: "http://localhost:3009" url: "http://localhost:3009"
clsi: clsi:
@ -93,6 +95,7 @@ module.exports =
apiKey: "" apiKey: ""
subdomain: "" subdomain: ""
templates: templates:
user_id: process.env.TEMPLATES_USER_ID or "5395eb7aad1f29a88756c7f2" user_id: process.env.TEMPLATES_USER_ID or "5395eb7aad1f29a88756c7f2"