Skip to content

Commit ef1c1f0

Browse files
Joonmo YangJoonmo Yang
authored andcommitted
Remove cckey context
1 parent 57d84ec commit ef1c1f0

File tree

6 files changed

+11
-52
lines changed

6 files changed

+11
-52
lines changed

bin/www.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44

55
import * as debugModule from "debug";
66
import { createApp } from "../src/app";
7-
import { closeContext } from "../src/context";
87
const debug = debugModule("faucet:server");
98
import * as http from "http";
109

1110
main();
1211

1312
async function main() {
1413
try {
15-
const [app, context] = await createApp();
14+
const app = await createApp();
1615

1716
/**
1817
* Get port from environment and store in Express.
@@ -51,8 +50,6 @@ async function main() {
5150
} catch (err) {
5251
console.error(`Error at closing ${err}`);
5352
} finally {
54-
console.log("Cleanup context");
55-
await closeContext(context);
5653
process.exit();
5754
}
5855
});

src/__test__/ping.spec.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
import { Application } from "express";
22
import * as request from "supertest";
33
import { createApp } from "../app";
4-
import { closeContext, Context } from "../context";
54

65
let app: Application;
7-
let context: Context;
86

97
beforeEach(async () => {
10-
const res = await createApp();
11-
app = res[0];
12-
context = res[1];
13-
});
14-
15-
afterEach(async () => {
16-
await closeContext(context);
8+
app = await createApp();
179
});
1810

1911
test("ping", async () => {

src/app.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import { Model } from "objection";
77
import * as path from "path";
88
const morganBody = require("morgan-body");
99

10-
import { Context, createContext } from "./context";
1110
import { createRouter as createApiRouter } from "./routes/api";
1211
import { createRouter as createPingRouter } from "./routes/ping";
1312

14-
export async function createApp(): Promise<[express.Application, Context]> {
13+
export async function createApp(): Promise<express.Application> {
1514
Model.knex(knex(config.get("knex")));
1615
const app = express();
1716

@@ -24,9 +23,8 @@ export async function createApp(): Promise<[express.Application, Context]> {
2423
app.use(express.static(path.join(__dirname, "public")));
2524
morganBody(app);
2625

27-
const context = await createContext();
28-
app.use("/api", createApiRouter(context));
29-
app.use("/ping", createPingRouter(context));
26+
app.use("/api", createApiRouter());
27+
app.use("/ping", createPingRouter());
3028

3129
// catch 404 and forward to error handler
3230
app.use((req, res, next) => {
@@ -44,5 +42,5 @@ export async function createApp(): Promise<[express.Application, Context]> {
4442
res.status(err.status || 500);
4543
res.render("error");
4644
});
47-
return [app, context];
45+
return app;
4846
}

src/context.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/routes/api.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
signEcdsa
88
} from "codechain-primitives";
99
import * as express from "express";
10-
import { Context } from "../context";
1110
import KeyModel from "../models/key";
1211

1312
type KeyType = "asset" | "platform";
@@ -19,7 +18,7 @@ function findKey(
1918
return KeyModel.query().findById([type, address]) as any;
2019
}
2120

22-
export function createRouter(context: Context) {
21+
export function createRouter() {
2322
const router = express.Router();
2423

2524
router.get("/keys", async (req, res) => {

src/routes/ping.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
import * as express from "express";
2-
import { Context } from "../context";
32

4-
export function createRouter(context: Context) {
3+
export function createRouter() {
54
const router = express.Router();
65

76
router.get("/", async (req, res) => {
8-
try {
9-
await context.cckey.platform.getKeys();
10-
res.json({
11-
success: true
12-
});
13-
} catch (err) {
14-
res.json({
15-
success: false,
16-
error: err
17-
});
18-
}
7+
res.json({
8+
success: true
9+
});
1910
});
2011

2112
return router;

0 commit comments

Comments
 (0)