salix/services/mailer/application/router.js

31 lines
832 B
JavaScript
Raw Normal View History

2017-05-30 06:06:14 +00:00
var express = require('express');
var router = new express.Router();
var fs = require('fs');
var path = require('path');
2017-05-30 06:06:14 +00:00
2017-06-07 13:28:42 +00:00
// Mailer default page
2017-05-30 06:06:14 +00:00
router.get('/', function(request, response) {
response.json({});
2017-05-30 06:06:14 +00:00
});
2017-06-07 13:28:42 +00:00
// Notifications
router.use('/notification', require('./route/notification.js'));
2017-05-30 06:06:14 +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-05-30 06:06:14 +00:00
module.exports = router;