diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2023-03-30 01:09:30 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2023-03-30 01:09:30 +0300 |
commit | e2da6d2db20093ebd2a65aad35c9991ab1a02176 (patch) | |
tree | e5c77a8f4a6fd106b13b659e248cab5768d07cdc /api/routes/index.js | |
parent | a4901ad47d2945e9a6c6616661840c97ebbf03e7 (diff) | |
download | arching-kaos-tools-e2da6d2db20093ebd2a65aad35c9991ab1a02176.tar.gz arching-kaos-tools-e2da6d2db20093ebd2a65aad35c9991ab1a02176.tar.bz2 arching-kaos-tools-e2da6d2db20093ebd2a65aad35c9991ab1a02176.zip |
Introducing an HTTP JSON API
Diffstat (limited to 'api/routes/index.js')
-rw-r--r-- | api/routes/index.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/api/routes/index.js b/api/routes/index.js new file mode 100644 index 0000000..b771758 --- /dev/null +++ b/api/routes/index.js @@ -0,0 +1,43 @@ +const settings = require('../settings'); +const {Router} = require('express'); +const cors = require('cors'); +const hi = require('./default'); +const seeNSEntriesFile = require('./showNSEntriesFile'); +const seeEntriesFile = require('./showEntriesFile'); +const getSLatest = require('./getSLatest'); +const getZLatest = require('./getZLatest'); +const getSBlock = require('./getSBlock'); +const getZChain = require('./getZChain'); +const receiveZBlock = require('./receiveZBlock'); +const receiveZChain = require('./receiveZChain'); +const corsOptions = { + origin: '*', + optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204 +}; +const router = new Router(); +// Basic route, welcomes and provides the available routes to the visitor +router.route('/').get(hi); + +/* + * Replies with contents of files + * + */ +// Gathered zchain zlatest pairs +router.route(settings.URL_PREFIX+'/seens').get(seeNSEntriesFile); +// Gathered zblocks +router.route(settings.URL_PREFIX+'/see').get(seeEntriesFile); +// Latest known mined block +router.route(settings.URL_PREFIX+'/slatest').get(getSLatest); +// Shows a mined block (provided that /sblock?sblock=SHA512 hash) +router.route(settings.URL_PREFIX+'/sblock').get(getSBlock); +// Outputs node's local chain +router.route(settings.URL_PREFIX+'/zchain').get(getZChain); +// Returns latest zblock from node's local chain +router.route(settings.URL_PREFIX+'/zlatest').get(getZLatest); +// Send a block to the node (zchain block) +router.route(settings.URL_PREFIX+'/sblk').post(receiveZBlock); +// Send a zchain link to the node (refering to a valid zchain out there) +router.route(settings.URL_PREFIX+'/szch').post(receiveZChain); + +router.route('/*').get((req,res)=>{console.log(req.url);res.send({errno:"404"})}); +module.exports = router; |