Add homepage

This commit is contained in:
Wietse Wind
2023-10-06 12:42:53 +02:00
parent 6cb063e6e3
commit eef8cae0a7
4 changed files with 149 additions and 81 deletions

View File

@@ -3,6 +3,7 @@ import morgan from 'morgan'
import express from 'express'
import expressWs from 'express-ws'
import autoindex from 'express-autoindex/dist/index.cjs.js'
import nunjucks from 'nunjucks'
import 'dotenv/config'
import { lastLedger } from '../lib/onLedger.mjs'
@@ -20,6 +21,8 @@ if (!wss) {
try {
const app = express()
nunjucks.configure(new URL('../', import.meta.url).pathname, { autoescape: true, express: app })
app.enable('trust proxy')
app.disable('x-powered-by')
app.use(express.json())
@@ -31,7 +34,28 @@ if (!wss) {
// return next()
// })
app.use('/', express.static('./store/'))
app.use('/', function renderHomepage(req, res, next) {
res.setHeader('content-type', 'text/html');
if (req.url === '' || req.url === '/') {
res.render('public_html/index.html', {
config: {
networkid: process.env?.NETWORKID ?? null,
urlprefix: process.env?.URL_PREFIX ?? null,
nodes: process.env?.NODES ?? null,
fields: process.env?.FIELDSREQUIRED ?? null,
unlurl: process.env?.UNLURL ?? null,
unlkey: process.env?.UNLKEY ?? null,
},
stats: {
lastLedger: lastLedger ?? null,
lastLedgerTx: lastLedgerTx ?? null,
txCount: txCount ?? null,
},
})
} else {
next()
}
},express.static('./store/'))
app.use('/health', (req, res) => {
res.json({
@@ -82,8 +106,8 @@ const emit = _data => {
// console.log(client?._xpopBlob)
let account = ''
const accountAddress = client.req.url.match(/r[a-zA-Z0-9]{18,}/)
const blob = !!client.req.url.match(/\/blob/i)
const accountAddress = client.req?.url.match(/r[a-zA-Z0-9]{18,}/)
const blob = !!client.req?.url.match(/\/blob/i)
if (accountAddress) {
account = accountAddress[0]

123
package-lock.json generated
View File

@@ -17,9 +17,9 @@
"express-ws": "^5.0.2",
"morgan": "^1.10.0",
"node-fetch": "^3.3.2",
"nunjucks": "^3.2.4",
"ripple-address-codec": "^4.3.0",
"ripple-binary-codec": "^1.10.0",
"serve-index": "^1.9.1",
"ws": "^8.14.2",
"xrpl-client": "^2.2.0"
},
@@ -37,6 +37,11 @@
"integrity": "sha512-g5QiLIfbg3pLuYUJPlisNKY+epQJTcMDsOnVNkscrDP1oi7vmJnzOANYJI/1pZcVJ6umUkBv3aFtlg1UvUHGzA==",
"dev": true
},
"node_modules/a-sync-waterfall": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/a-sync-waterfall/-/a-sync-waterfall-1.0.1.tgz",
"integrity": "sha512-RYTOHHdWipFUliRFMCS4X2Yn2X8M87V/OpSqWzKKOGhzqyUxzyVmhHDH9sAvG+ZuQf/TAOFsLCpMw09I1ufUnA=="
},
"node_modules/accepts": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
@@ -171,6 +176,11 @@
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
"peer": true
},
"node_modules/asap": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
"integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA=="
},
"node_modules/assert": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/assert/-/assert-2.1.0.tgz",
@@ -243,11 +253,6 @@
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"node_modules/batch": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz",
"integrity": "sha512-x+VAiMRL6UPkx+kudNvxTl6hB2XNNCG2r+7wixVfIYwu/2HKRXimwQyaumLjMveWvT2Hkd/cAJw+QBMfJ/EKVw=="
},
"node_modules/big-integer": {
"version": "1.6.51",
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz",
@@ -541,6 +546,14 @@
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"node_modules/commander": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-5.1.0.tgz",
"integrity": "sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==",
"engines": {
"node": ">= 6"
}
},
"node_modules/compressible": {
"version": "2.0.18",
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
@@ -848,7 +861,8 @@
"node_modules/escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow=="
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
"peer": true
},
"node_modules/etag": {
"version": "1.8.1",
@@ -1752,6 +1766,30 @@
"node": ">=8"
}
},
"node_modules/nunjucks": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/nunjucks/-/nunjucks-3.2.4.tgz",
"integrity": "sha512-26XRV6BhkgK0VOxfbU5cQI+ICFUtMLixv1noZn1tGU38kQH5A5nmmbk/O45xdyBhD1esk47nKrY0mvQpZIhRjQ==",
"dependencies": {
"a-sync-waterfall": "^1.0.0",
"asap": "^2.0.3",
"commander": "^5.1.0"
},
"bin": {
"nunjucks-precompile": "bin/precompile"
},
"engines": {
"node": ">= 6.9.0"
},
"peerDependencies": {
"chokidar": "^3.3.0"
},
"peerDependenciesMeta": {
"chokidar": {
"optional": true
}
}
},
"node_modules/object-inspect": {
"version": "1.12.3",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz",
@@ -1840,6 +1878,7 @@
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
"peer": true,
"engines": {
"node": ">= 0.8"
}
@@ -2169,76 +2208,6 @@
"node": ">= 0.6"
}
},
"node_modules/serve-index": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/serve-index/-/serve-index-1.9.1.tgz",
"integrity": "sha512-pXHfKNP4qujrtteMrSBb0rc8HJ9Ms/GrXwcUtUtD5s4ewDJI8bT3Cz2zTVRMKtri49pLx2e0Ya8ziP5Ya2pZZw==",
"dependencies": {
"accepts": "~1.3.4",
"batch": "0.6.1",
"debug": "2.6.9",
"escape-html": "~1.0.3",
"http-errors": "~1.6.2",
"mime-types": "~2.1.17",
"parseurl": "~1.3.2"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/serve-index/node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dependencies": {
"ms": "2.0.0"
}
},
"node_modules/serve-index/node_modules/depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/serve-index/node_modules/http-errors": {
"version": "1.6.3",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
"integrity": "sha512-lks+lVC8dgGyh97jxvxeYTWQFvh4uw4yC12gVl63Cg30sjPX4wuGcdkICVXDAESr6OJGjqGA8Iz5mkeN6zlD7A==",
"dependencies": {
"depd": "~1.1.2",
"inherits": "2.0.3",
"setprototypeof": "1.1.0",
"statuses": ">= 1.4.0 < 2"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/serve-index/node_modules/inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw=="
},
"node_modules/serve-index/node_modules/ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
},
"node_modules/serve-index/node_modules/setprototypeof": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz",
"integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ=="
},
"node_modules/serve-index/node_modules/statuses": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/serve-static": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz",

View File

@@ -11,8 +11,9 @@
"author": "Wietse Wind <w@xrpl-labs.com>",
"license": "MIT",
"nodemonConfig": {
"ext": "js,mjs,cjs,html",
"ignore": [
"store/*"
"/store/**"
]
},
"dependencies": {
@@ -24,6 +25,7 @@
"express-ws": "^5.0.2",
"morgan": "^1.10.0",
"node-fetch": "^3.3.2",
"nunjucks": "^3.2.4",
"ripple-address-codec": "^4.3.0",
"ripple-binary-codec": "^1.10.0",
"ws": "^8.14.2",

73
public_html/index.html Normal file
View File

@@ -0,0 +1,73 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Validation Ledger &amp; Transaction Store</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1 class="h2 pt-2">Validation Ledger &amp; Transaction Store</h1>
<div class="row">
<div class="col-12 col-md-4">
<div class="alert alert-warning">
This service collects validation messages, ledger &amp; transaction information
and stores &amp; serves the raw data, and generated
<code><a href="https://github.com/XRPLF/XRPL-Standards/discussions/107">xPOP</a></code> blobs.
</div>
</div>
<div class="col-12 col-md-8">
<div class="alert alert-warning">
<ul class="mb-0 ps-3">
<li>
<a href="{{ config.urlprefix }}/xpop/...">xPOP storage location</a><br />
<code>{{ config.urlprefix }}/xpop/{ hash }</code>
</li>
<li>
<a href="{{ config.urlprefix }}/{{ config.networkid }}/">Browse source data (per ledger)</a><br />
<code>{{ config.urlprefix }}/{{ config.networkid }}/...</code>
</li>
<li>
<a href="{{ config.urlprefix }}/health">Health / stats endpoint</a><br />
<code>{{ config.urlprefix }}/health</code>
</li>
<li>
<a href="{{ config.urlprefix.replace('http', 'ws') }}">xPOP event websocket</a><br />
<code>{{ config.urlprefix.replace('http', 'ws') }} (WEBSOCKET)</code>
</li>
<li>
<a href="{{ config.urlprefix.replace('http', 'ws') }}/blob">xPOP event websocket + Blob</a><br />
<code>{{ config.urlprefix.replace('http', 'ws') }}/blob (WEBSOCKET)</code>
</li>
<li>
<a href="{{ config.urlprefix.replace('http', 'ws') }}/blob/rAddress...">xPOP event websocket for specific account + Blob</a><br />
<code>{{ config.urlprefix.replace('http', 'ws') }}/blob/rAddress... (WEBSOCKET)</code>
</li>
</ul>
</div>
</div>
</div>
<h4 class="mt-2">Stats</h4>
<div class="card shadow-sm bg-primary text-white border-2">
<div class="card-body px-3 py-2">
<pre class="mb-0">{{ config|dump(2) }}</pre>
</div>
</div>
<h4 class="mt-2">Stats</h4>
<div class="card shadow-sm bg-primary text-white border-2">
<div class="card-body px-3 py-2">
<pre class="mb-0">{{ stats|dump(2) }}</pre>
</div>
</div>
<br />
Run your own instance: <a href="https://github.com/Xahau/Validation-Ledger-Tx-Store-to-xPOP">Source</a>
</div>
</body>
</html>