-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpreview-server.js
More file actions
68 lines (61 loc) · 2.18 KB
/
Copy pathpreview-server.js
File metadata and controls
68 lines (61 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { readFileSync } from 'node:fs';
import { createServer } from 'node:http';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { compileEmailTemplate } from '../../dist/index.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const rootDir = join(__dirname, '..', '..');
const host = '127.0.0.1';
const port = Number(process.env.PORT || 4174);
async function main() {
const css = readFileSync(join(rootDir, 'examples', 'auth', 'shared.css'), 'utf8');
const html = readFileSync(join(rootDir, 'examples', 'marketing', 'feature-roundup.html'), 'utf8');
const template = await compileEmailTemplate({
subject: 'Three ACME upgrades for {{teamName}}',
html,
css
});
const server = createServer((request, response) => {
if (request.url !== '/' && request.url !== '/feature-roundup') {
response.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' });
response.end('Not found');
return;
}
const email = template.render({
data: {
appUrl: 'https://app.acme.example',
brandUrl: 'https://acme.example',
featureCount: 3,
featuresUrl: 'https://app.acme.example/features',
preferencesUrl: 'https://app.acme.example/settings/email',
teamName: 'Product Operations',
features: [
{
tone: 'info',
title: 'Shared decision trails',
description: 'Keep the context behind each decision close to the work it affects.'
},
{
tone: 'success',
title: 'Reusable handoff checklists',
description: 'Turn strong workflows into repeatable team habits.'
},
{
tone: 'warning',
title: 'Attention summaries',
description: 'Surface stalled work before it becomes a missed deadline.'
}
]
}
});
response.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
response.end(email.html);
});
server.listen(port, host, () => {
console.log(`Preview server: http://localhost:${port}/feature-roundup`);
});
}
main().catch((error) => {
console.error(error);
process.exit(1);
});