2014-07-30 10:44:03 -04:00
|
|
|
request = require("request")
|
|
|
|
settings = require("settings-sharelatex")
|
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
ErrorController = require "../Errors/ErrorController"
|
|
|
|
|
|
|
|
module.exports = WikiController =
|
|
|
|
getPage: (req, res, next) ->
|
|
|
|
page = req.url.replace(/^\/learn/, "").replace(/^\//, "")
|
|
|
|
if page == ""
|
|
|
|
page = "Main_Page"
|
|
|
|
|
2014-07-30 10:56:27 -04:00
|
|
|
wikiUrl = "#{settings.apis.wiki.url}/learn-scripts/api.php"
|
2014-07-30 10:44:03 -04:00
|
|
|
|
|
|
|
logger.log page: page, "proxying request to wiki"
|
|
|
|
|
|
|
|
request {
|
|
|
|
url: wikiUrl
|
|
|
|
qs: {
|
2014-07-31 08:12:24 -04:00
|
|
|
page: decodeURI(page)
|
2014-07-30 10:44:03 -04:00
|
|
|
action: "parse"
|
|
|
|
format: "json"
|
|
|
|
}
|
|
|
|
}, (err, response, data)->
|
|
|
|
if response?.statusCode == 404
|
|
|
|
return ErrorController.notFound(req, res, next)
|
|
|
|
try
|
|
|
|
data = JSON.parse(data)
|
|
|
|
catch err
|
|
|
|
logger.err err:err, data:data, "error parsing data from wiki"
|
|
|
|
logger.log data: data, "got response from wiki"
|
|
|
|
res.render "wiki/page", {
|
|
|
|
content: data.parse.text['*']
|
|
|
|
title: data.parse.title
|
|
|
|
}
|