Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove websocket connection #338

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ export default {
txsHashesRequestLimit: 150,
},
safeBlockDifference: process.env.SAFE_BLOCK_DIFFERENCE || "10",
usingQueueEndpoint: process.env.USE_SIGNED_TX_QUEUE || "false"
usingQueueEndpoint: process.env.USE_SIGNED_TX_QUEUE || "false",
sentry: {
enabled: process.env.SENTRY_ENABLED || "true",
tracesSampleRate: process.env.SENTRY_TRACES_SAMPLE_RATE || "0.01"
}
};
11 changes: 1 addition & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"semver-compare": "^1.0.0",
"ts-node": "^9.0.0",
"tsc-watch": "^4.2.9",
"typescript": "^4.0.5",
"ws": "^7.4.2"
"typescript": "^4.0.5"
},
"devDependencies": {
"@types/chai": "^4.2.14",
Expand All @@ -55,7 +54,6 @@
"@types/pg": "^7.14.5",
"@types/ramda": "github:types/npm-ramda#dist",
"@types/semver-compare": "^1.0.1",
"@types/ws": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"eslint": "^7.12.1",
Expand Down
56 changes: 29 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import config from "config";
import http from "http";
import express from "express";
import * as websockets from "ws";
import { Request, Response } from "express";

import { Pool } from "pg";

// eslint-disable-next-line
const semverCompare = require("semver-compare");

import { connectionHandler } from "./ws-server";
import {
applyMiddleware,
applyRoutes,
Expand Down Expand Up @@ -66,6 +64,8 @@ import { mapTransactionFragsToResponse } from "./utils/mappers";
import * as Sentry from "@sentry/node";
import * as Tracing from "@sentry/tracing";

const sentryEnabled = config.get("sentry.enabled") === "true";

const pool = new Pool({
user: config.get("db.user"),
host: config.get("db.host"),
Expand All @@ -83,28 +83,30 @@ const healthChecker = new HealthChecker(() => askBestBlock(pool));

const router = express();

Sentry.init({
dsn: process.env.DSNExpress,
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// enable Express.js middleware tracing
new Tracing.Integrations.Express({
// to trace all requests to the default router
router,
// alternatively, you can specify the routes you want to trace:
// router: someRouter,
}),
new Tracing.Integrations.Postgres(),
],

// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: 1.0,
});
if (sentryEnabled) {
Sentry.init({
dsn: process.env.DSNExpress,
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// enable Express.js middleware tracing
new Tracing.Integrations.Express({
// to trace all requests to the default router
router,
// alternatively, you can specify the routes you want to trace:
// router: someRouter,
}),
new Tracing.Integrations.Postgres(),
],

// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: parseFloat(config.get("sentry.tracesSampleRate")),
});

router.use(Sentry.Handlers.requestHandler());
router.use(Sentry.Handlers.tracingHandler());
router.use(Sentry.Handlers.requestHandler());
router.use(Sentry.Handlers.tracingHandler());
}

const middlewares = [
middleware.handleCors,
Expand Down Expand Up @@ -456,11 +458,11 @@ const routes: Route[] = [
applyRoutes(routes, router);
router.use(middleware.logErrors);
router.use(middleware.errorHandler);
router.use(Sentry.Handlers.errorHandler());

const server = http.createServer(router);
if (sentryEnabled) {
router.use(Sentry.Handlers.errorHandler());
}

const wss = new websockets.Server({ server });
wss.on("connection", connectionHandler(pool));
const server = http.createServer(router);

server.listen(port, () => console.log(`listening on ${port}...`));