2017-05-30 06:06:14 +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-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) {
|
2017-10-17 06:22:59 +00:00
|
|
|
response.json({});
|
2017-05-30 06:06:14 +00:00
|
|
|
});
|
|
|
|
|
2017-06-07 13:28:42 +00:00
|
|
|
// Notifications
|
2017-06-01 06:51:29 +00:00
|
|
|
router.use('/notification', require('./route/notification.js'));
|
2017-05-30 06:06:14 +00:00
|
|
|
|
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);
|
2018-09-03 11:54:18 +00:00
|
|
|
|
2017-12-26 09:02:47 +00:00
|
|
|
readStream.on('open', function() {
|
2018-09-03 11:54:18 +00:00
|
|
|
let contentType = getContentType(imagePath);
|
|
|
|
|
|
|
|
if (contentType)
|
|
|
|
response.setHeader('Content-type', getContentType(imagePath));
|
|
|
|
|
2017-12-26 09:02:47 +00:00
|
|
|
readStream.pipe(response);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-09-03 11:54:18 +00:00
|
|
|
function getContentType(path) {
|
|
|
|
let types = {
|
|
|
|
png: 'image/png',
|
|
|
|
svg: 'image/svg+xml',
|
|
|
|
gif: 'image/gif',
|
|
|
|
jpeg: 'image/jpeg',
|
|
|
|
jpg: 'image/jpeg'
|
|
|
|
};
|
|
|
|
|
|
|
|
let extension = path.split('.')[1];
|
|
|
|
|
|
|
|
return types[extension];
|
|
|
|
}
|
|
|
|
|
2017-05-30 06:06:14 +00:00
|
|
|
module.exports = router;
|