2018-11-02 19:15:27 +03:00
|
|
|
'use strict'
|
|
|
|
const express = require('express')
|
2022-08-19 06:15:54 +03:00
|
|
|
const helmet = require('helmet')
|
2022-09-15 09:19:08 +03:00
|
|
|
const { getEmailMockup, sendTestEmail, notFound } = require('../controllers/email-l10n')
|
2022-08-19 06:15:54 +03:00
|
|
|
const { requireAdminUser } = require('../middleware')
|
|
|
|
const csrf = require('csurf')
|
|
|
|
|
|
|
|
const csrfProtection = csrf()
|
2018-11-02 19:15:27 +03:00
|
|
|
const router = express.Router()
|
2022-08-19 06:15:54 +03:00
|
|
|
const cspUnsafeInline = {
|
|
|
|
directives: {
|
2022-09-15 09:19:08 +03:00
|
|
|
defaultSrc: ["'self'"],
|
|
|
|
scriptSrc: ["'self'"],
|
|
|
|
styleSrc: ["'self'", "'unsafe-inline'"],
|
|
|
|
imgSrc: ["'self'", 'https://monitor.cdn.mozilla.net/'],
|
2022-10-04 06:56:12 +03:00
|
|
|
objectSrc: ["'none'"],
|
2022-09-15 09:19:08 +03:00
|
|
|
formAction: ["'self'"]
|
2022-08-19 06:15:54 +03:00
|
|
|
}
|
|
|
|
}
|
2018-11-02 19:15:27 +03:00
|
|
|
|
2022-09-15 09:19:08 +03:00
|
|
|
// Route needs unsafe-inline because inline styles are required as best-practice for HTML email styling.
|
|
|
|
// Route requires admin user and is not enabled for production.
|
|
|
|
router.get('/', requireAdminUser, csrfProtection, helmet.contentSecurityPolicy(cspUnsafeInline), getEmailMockup)
|
|
|
|
router.post('/send-test-email', express.urlencoded({ extended: false }), csrfProtection, requireAdminUser, sendTestEmail)
|
2018-11-03 00:21:08 +03:00
|
|
|
router.use(notFound)
|
2018-11-02 19:15:27 +03:00
|
|
|
|
|
|
|
module.exports = router
|