mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-28 01:01:53 +00: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")
|
||||
logger = require("logger-sharelatex")
|
||||
_ = require("underscore")
|
||||
ErrorController = require "../Errors/ErrorController"
|
||||
|
||||
extensionsToProxy = [".png", ".xml", ".jpeg", ".json", ".zip", ".eps"]
|
||||
|
||||
module.exports = BlogController =
|
||||
|
||||
getPage: (req, res)->
|
||||
getPage: (req, res, next)->
|
||||
url = req.url?.toLowerCase()
|
||||
blogUrl = "#{settings.apis.blog.url}#{url}"
|
||||
|
||||
|
@ -19,6 +20,8 @@ module.exports = BlogController =
|
|||
|
||||
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)
|
||||
data = data.trim()
|
||||
try
|
||||
data = JSON.parse(data)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
should = require('chai').should()
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
|
@ -17,9 +16,11 @@ describe "BlogController", ->
|
|||
url:"http://blog.sharelatex.env"
|
||||
@request =
|
||||
get: sinon.stub()
|
||||
@ErrorController = {}
|
||||
@BlogController = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex":@settings
|
||||
"logger-sharelatex": log:->
|
||||
"../Errors/ErrorController": @ErrorController
|
||||
"request": @request
|
||||
|
||||
@req = {}
|
||||
|
@ -41,6 +42,17 @@ describe "BlogController", ->
|
|||
|
||||
@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)->
|
||||
@BlogController._directProxy = sinon.stub()
|
||||
@req.url = "/something.png"
|
||||
|
|
Loading…
Reference in a new issue