Skip to content
Snippets Groups Projects
Commit 36d508a4 authored by Felix Schmoll's avatar Felix Schmoll
Browse files

Allow Cross reference requests

parent c609f05c
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ app.use(bodyParser.urlencoded({
// serve only *.xhtml documents
app.use('/docs', function(req, res, next){
res.set('Access-Control-Allow-Origin', 'http://localhost:3000');
if(req.path.endsWith('.xhtml')){
next();
} else {
......@@ -92,6 +93,8 @@ app.get('/get_task', function(req, res){
// get a mode
var mode = ['annotate', 'review'][Math.random() > 0.5 ? 0 : 1]
res.set('Access-Control-Allow-Origin', 'http://localhost:3000');
// TODO: Serve a proper document and result
res.jsonp({
'id': jobname, // a job id. Should be posted as a job id to the result page.
......@@ -106,7 +109,7 @@ app.get('/get_task', function(req, res){
var server = http.Server(app);
var port = 3000 || process.env.port;
var port = 4000 || process.env.port;
server.listen(port, function(){
console.log('CorTeXDummy listening at '+port);
......
index.js~ 0 → 100644
// import some modules
var bodyParser = require("body-parser"),
express = require('express'),
http = require('http'),
fs = require("fs"),
path = require("path");
require("string.prototype.endswith");
// counter and prefix for jobs
var job_counter = 0;
var job_prefix = (new Date()).getTime();
var jobs = [];
// get the path for the docs and the dumps
var pathDocs = path.resolve(__dirname+'/docs');
var pathDumps = path.resolve(__dirname+'/dumps');
// Create a really simple API
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}))
// serve only *.xhtml documents
app.use('/docs', function(req, res, next){
if(req.path.endsWith('.xhtml')){
next();
} else {
res.status(404).send('Not found');
}
}, express.static('docs/'));
app.post('/dumps/', function(req, res, next){
// read post data from the body
var post_data = req.body || {};
var id, doc;
if(!post_data.hasOwnProperty('id')){
return res.jsonp({'success': false, 'message': "Missing 'id' parameter. "});
} else {
id = post_data.id;
}
if(jobs.indexOf(id) === -1){
return res.jsonp({'success': false, 'message': "Unknown JOB id. "})
}
if(!post_data.hasOwnProperty('content')){
return res.jsonp({'success': false, 'message': "Missing 'content' parameter. "});
} else {
content = post_data.content;
}
// remove this job from the jobs list
jobs.splice(jobs.indexOf(id));
try{
fs.writeFileSync(pathDumps + '/'+id+'.xhtml', content);
} catch(e) {
console.log(e);
return res.jsonp({'success': false, 'message': 'Unable to save file. '});
}
res.jsonp({
'success': true,
'path': '/dumps/'+id+'.xhtml'
});
});
app.use('/dumps', function(req, res, next){
if(req.path.endsWith('.xhtml')){
next();
} else {
res.status(404).send('Not found');
}
}, express.static('dumps/'));
app.get('/get_task', function(req, res){
// make a job id and name
var jobid = job_counter++;
var jobname = job_prefix+'_'+jobid
jobs.push(jobname);
// get a document
var documents = fs.readdirSync(pathDocs).filter(function(e,i){return e.endsWith('.xhtml');});
var doc = documents[jobid % documents.length];
// get a mode
var mode = ['annotate', 'review'][Math.random() > 0.5 ? 0 : 1]
// TODO: Serve a proper document and result
res.jsonp({
'id': jobname, // a job id. Should be posted as a job id to the result page.
'path': 'docs/'+doc, // the path to the document to annotate
'post': 'dumps/'+doc, // the path you want to post results to. Should contain a 'content' field with the document and a 'id' field with the job id
'mode': mode, // the mode. One of 'annotate', 'review'
'annotations': null, // might contain another path to existing annotations in the future
});
});
// TODO: Implement document dumping & re-reading
var server = http.Server(app);
var port = 3000 || process.env.port;
server.listen(port, function(){
console.log('CorTeXDummy listening at '+port);
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment