-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from EYBlockchain/kahina/web3.init
New web3 connection using ServiceManager
- Loading branch information
Showing
10 changed files
with
121 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
|
||
import express from 'express'; | ||
import router from "./api_routes.mjs"; // import the routes | ||
import Web3 from './common/web3.mjs' | ||
import { ServiceManager } from './api_services.mjs'; | ||
import { Router } from './api_routes.mjs'; | ||
import Web3 from './common/web3.mjs'; | ||
ENCRYPTEDLISTENER_IMPORT | ||
|
||
const app = express(); | ||
|
||
app.use(express.json()); | ||
|
||
app.use('/', router); //to use the routes | ||
|
||
function gracefulshutdown() { | ||
console.log("Shutting down"); | ||
listener.close(() => { | ||
console.log("HTTP server closed."); | ||
process.exit(0); | ||
}); | ||
console.log('Shutting down'); | ||
listener.close(() => { | ||
console.log('HTTP server closed.'); | ||
process.exit(0); | ||
}); | ||
} | ||
|
||
process.on("SIGTERM", gracefulshutdown); | ||
process.on("SIGINT", gracefulshutdown); | ||
process.on('SIGTERM', gracefulshutdown); | ||
process.on('SIGINT', gracefulshutdown); | ||
|
||
const app = express(); | ||
app.use(express.json()); | ||
|
||
const web3 = Web3.connection() | ||
ENCRYPTEDLISTENER_CALL | ||
const web3 = Web3.connection(); | ||
const serviceMgr = new ServiceManager(web3); | ||
serviceMgr.init().then(async () => { | ||
ENCRYPTEDLISTENER_CALL | ||
|
||
|
||
const listener = app.listen(process.env.PORT || 3000, () => { | ||
console.log('Your app is listening on port ' + listener.address().port) | ||
}) | ||
const router = new Router(serviceMgr); | ||
const r = router.addRoutes(); | ||
app.use('/', r); | ||
const listener = app.listen(process.env.PORT || 3000, () => { | ||
console.log('Your app is listening on port ' + listener.address().port); | ||
}); | ||
}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
import express from 'express'; | ||
import {service_FUNCTION_NAME} from "./api_services.mjs"; | ||
const router = express.Router(); | ||
|
||
export class Router { | ||
constructor(serviceMgr){ | ||
this.serviceMgr =serviceMgr; | ||
} | ||
|
||
addRoutes() { | ||
|
||
const router = express.Router(); | ||
|
||
//router.get('/database', serviceController.getAllCommitment); | ||
router.post('/FUNCTION_NAME', service_FUNCTION_NAME); | ||
router.post('/FUNCTION_NAME', this.serviceMgr.service_FUNCTION_NAME.bind(this.serviceMgr),); | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.