salix/services/print/application/router.js

32 lines
820 B
JavaScript

var express = require('express');
var router = new express.Router();
var fs = require('fs');
var path = require('path');
// 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);
});
});
});
module.exports = router;