-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.mjs
More file actions
40 lines (29 loc) · 1.17 KB
/
Copy pathserver.mjs
File metadata and controls
40 lines (29 loc) · 1.17 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
import express from 'express';
import http from 'http';
import path from 'path';
import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
import { BitqueryServer } from '@bitquery/tradingview-sdk/server';
import WebSocket from 'ws';
global.WebSocket = WebSocket;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
dotenv.config({ path: path.resolve(__dirname, '.env.local') });
const WEB_PORT = process.env.PORT ? Number(process.env.PORT) : 3000;
const WS_PORT = process.env.WS_PORT ? Number(process.env.WS_PORT) : 8081;
// Start Bitquery WebSocket server
const bitqueryServer = new BitqueryServer({
port: WS_PORT,
bitqueryEndpoint:'https://streaming.bitquery.io/eap',
apiKey: process.env.BITQUERY_OAUTH_TOKEN ,
});
bitqueryServer.init();
const server = express();
server.use(express.static(path.join(__dirname, 'public')));
server.use('/vendor', express.static(path.join(__dirname, 'node_modules')));
const httpServer = http.createServer(server);
httpServer.listen(WEB_PORT, (err) => {
if (err) throw err;
console.log(`> Web ready on http://localhost:${WEB_PORT}`);
console.log(`> WS ready on ws://localhost:${WS_PORT}`);
});