-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
127 lines (111 loc) · 3.39 KB
/
server.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import {createGzip} from 'zlib';
import {SitemapStream, streamToPromise} from 'sitemap';
import {config, getDirName} from './server.config.mjs';
import express from 'express';
const __dirname = getDirName(import.meta.url);
var app = express();
// set the view engine to ejs
app.set('view engine', 'ejs');
app.use("/dist", express.static(__dirname + "/dist"));
app.use("/img", express.static(__dirname + "/img"));
app.use("/aicookieclicker", express.static(__dirname + "/aicookieclicker"));
// index page
app.get('/', function (req, res) {
const att = {
title: 'Ernest Marcinko Official',
description: 'I do code and sometimes I create educational style YouTube videos for fun.'
};
res.render('pages/index', {
att: att,
});
});
app.get('/typewriter', function (req, res) {
const att = {
title: 'TypeWriter Effect Script by Ernest Marcinko',
description: 'Typewriter effect written in javascript. Easy to use, very fast, very small.'
};
res.render('pages/typewriter', {
att: att,
});
});
app.get('/mkbhd-panels', function (req, res) {
fetch("https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s"
).then(r => r.json()).then((r) => {
const images = [];
Object.values(r.data).forEach((v)=>{
if (v.dhd) {
images.push(v.dhd);
}
});
const att = {
title: 'All MKBHD Panels images in HD',
description: 'These are all images from MKBHD\'s Panels app in HD resolution.',
images: images
};
res.render('pages/mkbhd-panels', {
att: att,
});
});
});
app.get('/htmx-serverless', function (req, res) {
const att = {
title: 'HTMX without a Server',
description: 'HTMX Serverless is a small addon to define static HTMX request and responses without a Server'
};
res.render('pages/htmx-serverless', {
att: att,
});
});
app.get('/github-worth', function (req, res) {
const att = {
title: 'Get money for your github account',
description: 'See how much your fantastic github account is worth and get the money immediately'
};
res.render('pages/github-worth', {
att: att,
});
});
app.get('/flappybird', function (req, res) {
const att = {
title: 'Flappy Bird in TypeScript by Ernest Marcinko',
description: 'Play Flappy Bird online. Created in javascript, typescript using a canvas.'
};
res.render('pages/flappybird', {
att: att,
});
});
let sitemap;
app.get('/sitemap.xml', async function (req, res) {
res.header('content-type', 'application/xml');
res.header('content-encoding', 'gzip');
if (sitemap) {
res.send(sitemap)
return
}
try {
const smstream = new SitemapStream({hostname: config.hostname})
const pipeline = smstream.pipe(createGzip())
smstream.write({url: '/', changefreq: 'monthly', priority: 1});
smstream.write({url: '/typewriter', changefreq: 'monthly', priority: 0.6});
smstream.write({url: '/flappybird', changefreq: 'monthly', priority: 0.6});
smstream.write({url: '/htmx-serverless', changefreq: 'monthly', priority: 0.6});
smstream.write({url: '/aicookieclicker', changefreq: 'monthly', priority: 0.6});
// cache the response
streamToPromise(pipeline).then(sm => sitemap = sm)
smstream.end()
// show errors and response
pipeline.pipe(res).on('error', (e) => {
throw e
});
} catch (e) {
res.status(500).end()
console.log(e);
}
});
app.get('/robots.txt', function (req, res) {
res.header('content-type', 'text/plain');
res.render('pages/robots', {
att: {hostname: config.hostname},
});
});
app.listen(8081);