-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
87 lines (67 loc) · 2.33 KB
/
index.js
File metadata and controls
87 lines (67 loc) · 2.33 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Create with faucet
* Author: Aurelia
* Date: 2025/2/15
* Desc
*/
// const express = require('express');
// const app = express();
// const fs = require('fs');
// const path = require('path');
// const privateKey = fs.readFileSync(path.join(__dirname, './httpsCert/server.key'), 'utf8');
// const certificate = fs.readFileSync(path.join(__dirname, './httpsCert/server.crt'), 'utf8');
// const credentials = {key: privateKey, cert: certificate};
// const {port, timeout} = require('./config');
// const https = require('https').Server(credentials, app);
// https.timeout = timeout;
// const bodyParser = require('body-parser');
// const compression = require('compression');
// const session = require('express-session');
// app.use(session({
// secret: 'trustslink666',
// name: 'captcha',
// cookie: {
// maxAge: 100000 /*过期时间*/
// },
// }));
// // 压缩
// app.use(compression());
// app.use(express.static(path.join(__dirname, '/views')));
// app.use(bodyParser.json());
// app.use(bodyParser.urlencoded({extended: true}));
// const routes = require('./router/index');
// routes(app);
// require('./db/connect');
// //创建https服务器
// https.listen(port, function () {
// console.info(`Please open Internet explorer to access :https://localhost:${port}/`);
// });
// process.on('unhandledRejection', function (err) {
// console.error('catch exception:', err.stack);
// });
// process.on('uncaughtException', function (err) {
// console.error('catch exception:', err.stack);
// });
const express = require('express');
const config = require('./config');
const nostrRelay = require('./services/nostr/relay');
const eventProcessor = require('./services/nostr/eventProcessor');
const app = express();
app.use(express.json());
// Initialize Nostr relay connection
nostrRelay.connect();
// Handle incoming Nostr events
nostrRelay.on('event', async (event) => {
if (event.kind === config.nostr.mintEventKind) {
await eventProcessor.processMintEvent(event);
nostrRelay.updateLastProcessedTimestamp(event.created_at);
}
});
// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'ok', nostrConnected: nostrRelay.isConnected });
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});