Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
OutRed
GitHub Repository: OutRed/artclass
Path: blob/main/index.js
584 views
1
import { fileURLToPath } from 'node:url';
2
import { join } from 'node:path';
3
import { hostname } from 'node:os';
4
import { createServer } from 'node:http';
5
import createBareServer from '@tomphttp/bare-server-node';
6
import express from 'express';
7
// "@titaniumnetwork-dev/ultraviolet": "^1.0.5",
8
//import { uvPath } from '@titaniumnetwork-dev/ultraviolet';
9
import { getLastCommit } from 'git-last-commit';
10
import axios from 'axios';
11
12
getLastCommit((err, commit) => {
13
if (!err) console.log(`Latest update: ${commit.subject} (${commit.committer.name})`);
14
});
15
16
const publicPath = fileURLToPath(new URL('./static/', import.meta.url));
17
const bare = createBareServer('/bare/');
18
const server = createServer();
19
const app = express();
20
/*
21
Trust proxy by default, if you are self hosting and not behind a reverse proxy,
22
you should disable this.
23
*/
24
app.set('trust proxy', true);
25
let dataScript;
26
const port = process.env.PORT || 3000;
27
28
app.use(express.static(publicPath));
29
//app.use('/uv/', express.static(uvPath));
30
31
app.use((req, res) => res.status(404).sendFile(join(publicPath, '404.html')));
32
server.on('request', (req, res) => {
33
if (bare.shouldRoute(req)) {
34
bare.routeRequest(req, res);
35
} else {
36
app(req, res);
37
}
38
});
39
40
server.on('upgrade', (req, socket, head) => {
41
if (bare.shouldRoute(req)) {
42
bare.routeUpgrade(req, socket, head);
43
} else {
44
socket.end();
45
}
46
});
47
48
server.listen({ port }, () => {
49
console.log('Listening on:');
50
console.log(`\thttp://localhost:${server.address().port}`);
51
console.log(`\thttp://${hostname()}:${server.address().port}`);
52
console.log(
53
`\thttp://${
54
server.address().family === 'IPv6' ? `[${server.address().address}]` : server.address().address
55
}:${server.address().port}`
56
);
57
});
58
59