mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
45 lines
No EOL
1.3 KiB
CoffeeScript
45 lines
No EOL
1.3 KiB
CoffeeScript
request = require("request")
|
|
settings = require("settings-sharelatex")
|
|
logger = require("logger-sharelatex")
|
|
_ = require("underscore")
|
|
ErrorController = require "../Errors/ErrorController"
|
|
|
|
extensionsToProxy = [".png", ".xml", ".jpeg", ".json", ".zip", ".eps"]
|
|
|
|
module.exports = BlogController =
|
|
|
|
getPage: (req, res, next)->
|
|
url = req.url?.toLowerCase()
|
|
blogUrl = "#{settings.apis.blog.url}#{url}"
|
|
|
|
extensionsToProxy = [".png", ".xml", ".jpeg", ".json", ".zip", ".eps"]
|
|
|
|
shouldProxy = _.find extensionsToProxy, (extension)->
|
|
url.indexOf(extension) != -1
|
|
|
|
if shouldProxy
|
|
return BlogController._directProxy blogUrl, res
|
|
|
|
logger.log url:url, "proxying request to blog api"
|
|
request.get blogUrl, (err, r, data)->
|
|
if r?.statusCode == 404
|
|
return ErrorController.notFound(req, res, next)
|
|
if err?
|
|
return res.send 500
|
|
data = data.trim()
|
|
try
|
|
data = JSON.parse(data)
|
|
catch err
|
|
logger.err err:err, data:data, "error parsing data from data"
|
|
res.render "blog/blog_holder", data
|
|
|
|
|
|
getIndexPage: (req, res)->
|
|
req.url = "/blog/index.html"
|
|
BlogController.getPage req, res
|
|
|
|
_directProxy: (originUrl, res)->
|
|
upstream = request.get(originUrl)
|
|
upstream.on "error", (error) ->
|
|
logger.error err: error, "blog proxy error"
|
|
upstream.pipe res |