mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 04:45:21 -05:00
blog returns 404's if the page does not exist in blog
This commit is contained in:
parent
83b94f987c
commit
17962426ea
2 changed files with 17 additions and 2 deletions
|
@ -2,12 +2,13 @@ request = require("request")
|
||||||
settings = require("settings-sharelatex")
|
settings = require("settings-sharelatex")
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
_ = require("underscore")
|
_ = require("underscore")
|
||||||
|
ErrorController = require "../Errors/ErrorController"
|
||||||
|
|
||||||
extensionsToProxy = [".png", ".xml", ".jpeg", ".json", ".zip", ".eps"]
|
extensionsToProxy = [".png", ".xml", ".jpeg", ".json", ".zip", ".eps"]
|
||||||
|
|
||||||
module.exports = BlogController =
|
module.exports = BlogController =
|
||||||
|
|
||||||
getPage: (req, res)->
|
getPage: (req, res, next)->
|
||||||
url = req.url?.toLowerCase()
|
url = req.url?.toLowerCase()
|
||||||
blogUrl = "#{settings.apis.blog.url}#{url}"
|
blogUrl = "#{settings.apis.blog.url}#{url}"
|
||||||
|
|
||||||
|
@ -19,6 +20,8 @@ module.exports = BlogController =
|
||||||
|
|
||||||
logger.log url:url, "proxying request to blog api"
|
logger.log url:url, "proxying request to blog api"
|
||||||
request.get blogUrl, (err, r, data)->
|
request.get blogUrl, (err, r, data)->
|
||||||
|
if r?.statusCode == 404
|
||||||
|
return ErrorController.notFound(req, res, next)
|
||||||
data = data.trim()
|
data = data.trim()
|
||||||
try
|
try
|
||||||
data = JSON.parse(data)
|
data = JSON.parse(data)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
should = require('chai').should()
|
should = require('chai').should()
|
||||||
SandboxedModule = require('sandboxed-module')
|
SandboxedModule = require('sandboxed-module')
|
||||||
assert = require('assert')
|
assert = require('assert')
|
||||||
|
@ -17,9 +16,11 @@ describe "BlogController", ->
|
||||||
url:"http://blog.sharelatex.env"
|
url:"http://blog.sharelatex.env"
|
||||||
@request =
|
@request =
|
||||||
get: sinon.stub()
|
get: sinon.stub()
|
||||||
|
@ErrorController = {}
|
||||||
@BlogController = SandboxedModule.require modulePath, requires:
|
@BlogController = SandboxedModule.require modulePath, requires:
|
||||||
"settings-sharelatex":@settings
|
"settings-sharelatex":@settings
|
||||||
"logger-sharelatex": log:->
|
"logger-sharelatex": log:->
|
||||||
|
"../Errors/ErrorController": @ErrorController
|
||||||
"request": @request
|
"request": @request
|
||||||
|
|
||||||
@req = {}
|
@req = {}
|
||||||
|
@ -41,6 +42,17 @@ describe "BlogController", ->
|
||||||
|
|
||||||
@BlogController.getPage @req, @res
|
@BlogController.getPage @req, @res
|
||||||
|
|
||||||
|
it "should send to the error controller if the blog responds 404", (done)->
|
||||||
|
@req.url = "/blog/something.html"
|
||||||
|
@request.get.callsArgWith(1, null, {statusCode:404})
|
||||||
|
|
||||||
|
@ErrorController.notFound = (req, res)=>
|
||||||
|
assert.deepEqual req, @req
|
||||||
|
assert.deepEqual res, @res
|
||||||
|
done()
|
||||||
|
|
||||||
|
@BlogController.getPage @req, @res
|
||||||
|
|
||||||
it "should proxy the image urls", (done)->
|
it "should proxy the image urls", (done)->
|
||||||
@BlogController._directProxy = sinon.stub()
|
@BlogController._directProxy = sinon.stub()
|
||||||
@req.url = "/something.png"
|
@req.url = "/something.png"
|
||||||
|
|
Loading…
Reference in a new issue