2017-11-27 14:08:18 +00:00
|
|
|
var express = require('express');
|
|
|
|
var router = new express.Router();
|
2017-12-26 09:02:47 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
2017-11-27 14:08:18 +00:00
|
|
|
|
|
|
|
// Default page
|
|
|
|
router.get('/', function(request, response) {
|
|
|
|
response.json({});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Manuscripts
|
|
|
|
router.use('/manuscript', require('./route/manuscript.js'));
|
|
|
|
|
2017-12-26 09:02:47 +00:00
|
|
|
// Serve static images
|
|
|
|
router.use('/static/:template/:image', function(request, response) {
|
|
|
|
let imagePath = path.join(__dirname, '/template/', request.params.template, '/image/', request.params.image);
|
|
|
|
|
|
|
|
fs.stat(imagePath, function(error) {
|
|
|
|
if (error)
|
|
|
|
return response.json({message: 'Image not found'});
|
|
|
|
|
|
|
|
let readStream = fs.createReadStream(imagePath);
|
|
|
|
|
|
|
|
readStream.on('open', function() {
|
|
|
|
readStream.pipe(response);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-11-27 14:08:18 +00:00
|
|
|
module.exports = router;
|