-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathapp.js
More file actions
53 lines (44 loc) · 1.47 KB
/
Copy pathapp.js
File metadata and controls
53 lines (44 loc) · 1.47 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
/**
* Alto Node Web Studio Server
*/
import express from 'express';
import cors from 'cors';
import path from 'path';
import { fileURLToPath } from 'url';
import { ALTO_CONFIG } from '../config.js';
import { defaultAltoRunner } from '../core/node-runner.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const WEB_ROOT = path.join(__dirname, '../../web');
const app = express();
const PORT = process.env.PORT || 3420;
app.use(cors());
app.use(express.json());
app.use(express.static(WEB_ROOT));
// 1. Get Node Info & Crates
app.get('/api/config', (req, res) => {
res.json({
node: ALTO_CONFIG.node,
crates: ALTO_CONFIG.crates,
metrics: ALTO_CONFIG.networkMetrics,
});
});
// 2. Produce Alto Block
app.post('/api/node/produce', (req, res) => {
const block = defaultAltoRunner.produceBlock();
res.json({ success: true, block });
});
// 3. Get Chain Blocks
app.get('/api/node/blocks', (req, res) => {
res.json(defaultAltoRunner.getRecentBlocks());
});
if (process.env.NODE_ENV !== 'test') {
app.listen(PORT, () => {
console.log(`\n======================================================`);
console.log(`🎶 Commonware Alto Reference Blockchain Studio Running!`);
console.log(`🌐 Web Dashboard: http://localhost:${PORT}`);
console.log(`⚡ Reference Implementation: Sub-Second Simplex Consensus`);
console.log(`======================================================\n`);
});
}
export default app;