Skip to content

Commit aa21e5a

Browse files
committed
fix(mail): mail prints to console in development
1 parent 75a3746 commit aa21e5a

File tree

9 files changed

+72
-23
lines changed

9 files changed

+72
-23
lines changed

CHANGELOG.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
<a name="1.0.0"></a>
2+
# [1.0.0](https://github.com/Beg-in/server/compare/1.0.0-beta.4...1.0.0) (2018-10-19)
3+
4+
5+
### Bug Fixes
6+
7+
* **mail:** mail prints to console in development ([4e35d36](https://github.com/Beg-in/server/commit/4e35d36))
8+
9+
10+
11+
<a name="1.0.0-beta.4"></a>
12+
# [1.0.0-beta.4](https://github.com/Beg-in/server/compare/1.0.0-beta.1...1.0.0-beta.4) (2018-10-16)
13+
14+
15+
### Bug Fixes
16+
17+
* **auth:** buffers for secure-password ([c9a9e75](https://github.com/Beg-in/server/commit/c9a9e75))
18+
* **db:** bump version for production properties fix ([75a3746](https://github.com/Beg-in/server/commit/75a3746))
19+
* **properties:** internal api overrides environment variables ([cd1a230](https://github.com/Beg-in/server/commit/cd1a230))
20+
21+
22+
### Features
23+
24+
* **roles:** add role system ([da312f0](https://github.com/Beg-in/server/commit/da312f0))
25+
26+
27+
28+
<a name="1.0.0-beta.1"></a>
29+
# [1.0.0-beta.1](https://github.com/Beg-in/server/compare/0.4.0...1.0.0-beta.1) (2018-10-11)
30+
31+
32+
133
<a name="0.4.0"></a>
234
# [0.4.0](https://github.com/Beg-in/server/compare/0.3.3...0.4.0) (2017-10-17)
335

@@ -45,7 +77,7 @@
4577

4678

4779
<a name="0.2.1"></a>
48-
## [0.2.1](https://github.com/Beg-in/server/compare/0.2.0...0.2.1) (2017-06-16)
80+
## [0.2.1](https://github.com/Beg-in/server/compare/0.1.3...0.2.1) (2017-06-16)
4981

5082

5183
### Bug Fixes
@@ -54,11 +86,6 @@
5486

5587

5688

57-
<a name="0.2.0"></a>
58-
# [0.2.0](https://github.com/Beg-in/server/compare/0.1.3...0.2.0) (2017-06-16)
59-
60-
61-
6289
<a name="0.1.3"></a>
6390
## [0.1.3](https://github.com/Beg-in/server/compare/0.1.2...0.1.3) (2017-06-13)
6491

auth/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ module.exports = {
146146
hash,
147147
verifyHash,
148148
getToken,
149+
decodeToken,
149150
test,
150151

151152
async access(ctx, config) {

mail/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ let sesTransport = require('nodemailer-ses-transport');
55
let properties = require('../properties');
66
let aws = require('../aws');
77
let renderer = require('../template');
8+
let log = require('../log');
89

910
const NAME = properties.mail.name(properties.name());
1011
const ADDRESS = properties.mail.address(`info@${properties.domain()}`);
1112
const FROM = `"${NAME}" <${ADDRESS}>`;
1213
const TRANSPORT = nodemailer.createTransport(sesTransport({ ses: aws.SES() }));
1314
const support = properties.mail.support(ADDRESS);
15+
const isDevelopment = properties.isDevelopment();
1416

15-
module.exports = (config, ...args) => {
17+
module.exports = async (config = {}) => {
1618
let {
1719
to,
1820
subject,
1921
template,
20-
options,
22+
options = {},
2123
} = config;
2224
let {
2325
from = FROM,
@@ -31,7 +33,10 @@ module.exports = (config, ...args) => {
3133
let locals = Object.assign({}, config);
3234
locals.mail = Object.assign({ support }, mail);
3335
if (template && !html) {
34-
html = renderer(template, locals, ...args);
36+
html = renderer(template, locals);
37+
}
38+
if (isDevelopment) {
39+
return log.debug(`Mail Sent to ${to}, open this link in your browser:`, `data:text/html;base64,${Buffer.from(html).toString('base64')}`);
3540
}
3641
return TRANSPORT.sendMail(Object.assign({ html }, options, mail));
3742
};

mail/template.pug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ html(lang="en")
55
block meta
66
title
77
block title
8-
| Notification from #{properties.name}
8+
| Notification from #{properties.name()}
99
body
1010
block greeting
1111
p Hello,
1212
block content
1313
block footer
14-
p If you believe this message has been sent to you in error or you are experiencing any issues please contact support at #[a(href=`mailto:${mail.support}`) #{properties.mail.support}].
14+
p If you believe this message has been sent to you in error or you are experiencing any issues please contact support at #[a(href=`mailto:${mail.support}`) #{mail.support}].

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "begin-server",
3-
"version": "1.0.0-beta.4",
3+
"version": "1.0.0",
44
"description": "Node.js server-side organizational framework",
55
"engines": {
66
"node": ">=7.6"

profile/change-password.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
extends ../mail/template
22

33
block content
4-
p You can reset your password by #[a(href=`https://${properties.domain}/password-reset?reset=${reset}`) clicking here].
4+
p You can reset your password by #[a(href=`${properties.build.root()}/auth?reset=${reset}`) clicking here].

profile/verify-email.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
extends ../mail/template
22

33
block content
4-
p Please verify your email address by #[a(href=`https://${properties.domain}/?verify=${verify}`) clicking here].
4+
p Please verify your email address by #[a(href=`${properties.build.root()}/?verify=${verify}`) clicking here].

properties/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,26 @@ const domain = process.env.SERVER_DOMAIN || (
2727
let production = properties.production || {};
2828
let config = STAGE === 'production' ? production : assignDeep(production, properties[STAGE] || {});
2929
let { build } = config;
30+
let port = +(process.env.PORT || (config.server && config.server.port) || 8081);
31+
build = Object.assign({
32+
cdn: `https://cdn.${domain}`,
33+
api: `https://api.${domain}`,
34+
root: `https://${domain}`,
35+
}, build);
36+
if (isDevelopment) {
37+
let url = process.env.SERVER_URL || (config.server && config.server.url) || 'http://localhost';
38+
let root = `${url}:${port - 1}`;
39+
build = Object.assign(build, {
40+
cdn: root,
41+
api: `${url}:${port}`,
42+
root,
43+
});
44+
}
3045
config = assignDeep(config.public || {}, config.server || {});
3146
const cwd = config.cwd ? path.join(process.cwd(), config.cwd()) : DIRECTORIES
3247
.map(dir => path.join(process.cwd(), dir))
3348
.find(dir => fs.existsSync(dir));
34-
let api = { isDevelopment, name, domain, build, cwd };
49+
let api = { isDevelopment, name, domain, build, cwd, port };
3550
config = Object.assign({}, config, api);
3651
let apiKeys = Object.keys(api);
3752
let props = location => new Proxy((fallback, devFallback) => {

template/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
let path = require('path');
44
let pug = require('pug');
5-
let rawProperties = require('../properties');
5+
let properties = require('../properties');
66

77
const MODULES = path.join(process.cwd(), 'node_modules');
8-
const properties = rawProperties();
98

10-
let compiled = {};
11-
module.exports = (file, { baseDir = MODULES, globals = { properties } } = {}) => {
12-
if (!compiled[file]) {
13-
compiled[file] = pug.compileFile(file, { baseDir, globals });
14-
}
15-
return compiled[file];
9+
module.exports = (filename, locals = {}) => {
10+
let { baseDir = MODULES } = locals;
11+
let compiled = pug.compileFile(filename, {
12+
baseDir,
13+
filename,
14+
cache: true,
15+
});
16+
return compiled(Object.assign({ properties }, locals));
1617
};

0 commit comments

Comments
 (0)