salix/services/print/application/router.js

32 lines
820 B
JavaScript
Raw Normal View History

2017-11-27 14:08:18 +00:00
var express = require('express');
var router = new express.Router();
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'));
// 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;