mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
blog intergration works
This commit is contained in:
parent
5cf756969e
commit
025d3147ec
6 changed files with 7832 additions and 8 deletions
|
@ -1,17 +1,35 @@
|
|||
request = require("request")
|
||||
settings = require("settings-sharelatex")
|
||||
logger = require("logger-sharelatex")
|
||||
_ = require("underscore")
|
||||
|
||||
module.exports =
|
||||
extensionsToProxy = [".png", ".xml", ".jpeg", ".json", ".zip", ".eps"]
|
||||
|
||||
module.exports = BlogController =
|
||||
|
||||
getPage: (req, res)->
|
||||
url = req.url
|
||||
url = req.url?.toLowerCase()
|
||||
blogUrl = "#{settings.apis.blog.url}#{url}"
|
||||
|
||||
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 "#{settings.apis.blog.url}#{url}", (err, r, data)->
|
||||
console.log data
|
||||
request.get blogUrl, (err, r, data)->
|
||||
data = data.trim()
|
||||
try
|
||||
data = JSON.parse(data)
|
||||
catch err
|
||||
logger.err err:err, data:data, "error parsing data from data"
|
||||
res.render "blog/#{data.layout}", data
|
||||
res.render "blog/blog_holder", data
|
||||
|
||||
|
||||
getIndexPage: (req, res)->
|
||||
req.url = "/blog/index.html"
|
||||
BlogController.getPage req, res
|
||||
|
||||
_directProxy: (originUrl, res)->
|
||||
request.get(originUrl).pipe res
|
|
@ -65,6 +65,7 @@ module.exports = class Router
|
|||
StaticPagesRouter.apply(app)
|
||||
TemplatesRouter.apply(app)
|
||||
|
||||
app.get '/blog', BlogController.getIndexPage
|
||||
app.get '/blog/*', BlogController.getPage
|
||||
|
||||
if Settings.enableSubscriptions
|
||||
|
|
4
services/web/app/views/blog/blog_holder.jade
Normal file
4
services/web/app/views/blog/blog_holder.jade
Normal file
|
@ -0,0 +1,4 @@
|
|||
extends ../layout
|
||||
|
||||
block content
|
||||
!{content}
|
|
@ -1,3 +0,0 @@
|
|||
div #{title}
|
||||
div #{author}
|
||||
div !{content}
|
7744
services/web/public/stylesheets/mainStyle.css
Normal file
7744
services/web/public/stylesheets/mainStyle.css
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,60 @@
|
|||
|
||||
should = require('chai').should()
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
path = require('path')
|
||||
sinon = require('sinon')
|
||||
modulePath = path.join __dirname, "../../../../app/js/Features/Blog/BlogController"
|
||||
expect = require("chai").expect
|
||||
|
||||
describe "BlogController", ->
|
||||
|
||||
beforeEach ->
|
||||
|
||||
@settings =
|
||||
apis:
|
||||
blog:
|
||||
url:"http://blog.sharelatex.env"
|
||||
@request =
|
||||
get: sinon.stub()
|
||||
@BlogController = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex":@settings
|
||||
"logger-sharelatex": log:->
|
||||
"request": @request
|
||||
|
||||
@req = {}
|
||||
@res = {}
|
||||
|
||||
|
||||
describe "getPage", ()->
|
||||
|
||||
it "should get the data from the blog api", (done)->
|
||||
@req.url = "/blog/something.html"
|
||||
body = {"stuff":"here"}
|
||||
|
||||
@request.get.callsArgWith(1, null, null, JSON.stringify(body))
|
||||
@res.render = (view, data)=>
|
||||
@request.get.calledWith("#{@settings.apis.blog.url}#{@req.url}")
|
||||
view.should.equal "blog/blog_holder"
|
||||
assert.deepEqual body, data
|
||||
done()
|
||||
|
||||
@BlogController.getPage @req, @res
|
||||
|
||||
it "should proxy the image urls", (done)->
|
||||
@BlogController._directProxy = sinon.stub()
|
||||
@req.url = "/something.png"
|
||||
@BlogController.getPage @req, @res
|
||||
@BlogController._directProxy.calledWith("#{@settings.apis.blog.url}#{@req.url}", @res).should.equal true
|
||||
done()
|
||||
|
||||
|
||||
describe "getIndexPage", ->
|
||||
|
||||
it "should change the url and send it to getPage", (done)->
|
||||
@req.url = "/blog"
|
||||
@BlogController.getPage = (req, res)->
|
||||
req.url.should.equal "/blog/index.html"
|
||||
done()
|
||||
@BlogController.getIndexPage @req, @res
|
||||
|
Loading…
Reference in a new issue