-
Notifications
You must be signed in to change notification settings - Fork 595
Expand file tree
/
Copy pathindex.ts
More file actions
49 lines (36 loc) · 1.28 KB
/
index.ts
File metadata and controls
49 lines (36 loc) · 1.28 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
#!/usr/bin/env -S node --no-warnings
import { createDebugLogger } from '@aztec/foundation/log';
import http from 'http';
import { type AztecNodeConfig, AztecNodeService, createAztecNodeRpcServer, getConfigEnvVars } from '../index.js';
const { AZTEC_NODE_PORT = 8081, API_PREFIX = '' } = process.env;
const logger = createDebugLogger('aztec:node');
/**
* Creates the node from provided config
*/
async function createAndDeployAztecNode() {
const aztecNodeConfig: AztecNodeConfig = { ...getConfigEnvVars() };
return await AztecNodeService.createAndSync(aztecNodeConfig);
}
/**
* Create and start a new Aztec Node HTTP Server
*/
async function main() {
logger.info(`Setting up Aztec Node...`);
const aztecNode = await createAndDeployAztecNode();
const shutdown = async () => {
logger.info('Shutting down...');
await aztecNode.stop();
process.exit(0);
};
process.once('SIGINT', shutdown);
process.once('SIGTERM', shutdown);
const rpcServer = createAztecNodeRpcServer(aztecNode);
const app = rpcServer.getApp(API_PREFIX);
const httpServer = http.createServer(app.callback());
httpServer.listen(+AZTEC_NODE_PORT);
logger.info(`Aztec Node JSON-RPC Server listening on port ${AZTEC_NODE_PORT}`);
}
main().catch(err => {
logger.error(err);
process.exit(1);
});