I'm currently developing an explorer for my own blockchain based on this project. The blockchain is developed upon parity-bitcoin. When I start the explorer using npm start, the error occurs: Supplied content type is not allowed. Content-Type: application/json is required.
I tested the API over Postman, and indeed the request goes correctly if I add Content-Type: application/json to the header. The debugging log showed that the request indeed does not include the header Content-Type: application/json, so I tried to manually add it in the code (at every place with new bitcoinCore()). However, the error remains. I'm wondering what is the right way of doing this?
Environment (please complete the following information):
Bitcoin Core / Node Version: Parity-bitcoin
NodeJS Version: 14.6.1
Browser: Crhome
Code Version / Commit: master
Configuration file content
# Optional logging settings, uncomment one of these example lines or add your own.
# See comments after each for more info.
# Default: "btcexp:app,btcexp:error"
DEBUG=* # Enable all logging, including middleware
# DEBUG=btcexp:* # Enable all logging specific to btc-rpc-explorer
# DEBUG=btcexp:app,btcexp:error # Default
# The base URL. If you want to run it elsewhere than on /, for example /btc-rpc-explorer/ - note that the value should include starting and ending "/"
# Default: /
#BTCEXP_BASEURL=/
#BTCEXP_BASEURL=/explorer/
# The active coin. Only officially supported value is "BTC".
# Default: BTC
#BTCEXP_COIN=BTC
# Host/Port to bind to
# Defaults: shown
#BTCEXP_HOST=127.0.0.1
#BTCEXP_PORT=3002
# Bitcoin RPC Credentials (URI -OR- HOST/PORT/USER/PASS)
# Defaults:
# - [host/port]: 127.0.0.1:8332
# - [username/password]: none
# - cookie: '~/.bitcoin/.cookie'
# - timeout: 5000 (ms)
#BTCEXP_BITCOIND_URI=bitcoin://rpcusername:rpcpassword@127.0.0.1:8332?timeout=10000
#BTCEXP_BITCOIND_HOST=127.0.0.1
#BTCEXP_BITCOIND_PORT=8332
#BTCEXP_BITCOIND_USER=rpcusername
#BTCEXP_BITCOIND_PASS=rpcpassword
#BTCEXP_BITCOIND_COOKIE=/path/to/bitcoind/.cookie
#BTCEXP_BITCOIND_RPC_TIMEOUT=5000
# Select optional "address API" to display address tx lists and balances
# Options: electrum, electrumx, blockchain.com, blockchair.com, blockcypher.com
#
# If this value is set to electrum (or the old value "electrumx"), then
# BTCEXP_ELECTRUM_SERVERS must also be set
#
# Default: none
#BTCEXP_ADDRESS_API=(electrum|electrumx|blockchain.com|blockchair.com|blockcypher.com)
# Optional Electrum Protocol Servers. See BTCEXP_ADDRESS_API. This value is only
# used if BTCEXP_ADDRESS_API=electrum (or the old value "electrumx")
#
# This variable was formerly named BTCEXP_ELECTRUMX_SERVERS and that name still works.
#
# Default: none
#BTCEXP_ELECTRUM_SERVERS=tls://electrumx.server.com:50002,tcp://127.0.0.1:50001,...
# Use the Electrum server as an external txindex. This is only available in the Electrs implementation.
#BTCEXP_ELECTRUM_TXINDEX=true
# Set number of concurrent RPC requests. Should be lower than your node's "rpcworkqueue" value.
# Note that Bitcoin Core's default rpcworkqueue=16.
# Default: 10
#BTCEXP_RPC_CONCURRENCY=10
# Disable app's in-memory RPC caching to reduce memory usage
# Default: false (i.e. in-memory cache **enabled**)
#BTCEXP_NO_INMEMORY_RPC_CACHE=true
# Optional redis server for RPC caching
# Default: none
#BTCEXP_REDIS_URL=redis://localhost:6379
# Default: hash of credentials
#BTCEXP_COOKIE_SECRET=0000aaaafffffgggggg
# Whether public-demo aspects of the site are active
# Default: false
#BTCEXP_DEMO=true
# Set to false to enable resource-intensive features, including:
# UTXO set summary querying
# (default value is true, i.e. resource-intensive features are disabled)
#BTCEXP_SLOW_DEVICE_MODE=false
# Privacy mode disables:
# Exchange-rate queries, IP-geolocation queries
# Default: false
#BTCEXP_PRIVACY_MODE=true
# Don't request currency exchange rates
# Default: true (i.e. no exchange-rate queries made)
#BTCEXP_NO_RATES=true
# Password protection for site via basic auth (enter any username, only the password is checked)
# Default: none
#BTCEXP_BASIC_AUTH_PASSWORD=mypassword
# File where the SSO token is stored; ignored if BTCEXP_BASIC_AUTH_PASSWORD is provided.
# Enables SSO if present.
# Default: none
#BTCEXP_SSO_TOKEN_FILE=/var/run/btc-rpc-explorer/sso_token
# URL of an optional external SSO provider
# This is ignored if SSO is not enabled (see BTCEXP_SSO_TOKEN_FILE)
# Default: none
#BTCEXP_SSO_LOGIN_REDIRECT_URL=/my-sso-provider/login
# Enable to allow access to all RPC methods
# Default: false
#BTCEXP_RPC_ALLOWALL=true
# Custom RPC method blacklist
# Default: (see config.js)
#BTCEXP_RPC_BLACKLIST=signrawtransaction,sendtoaddress,stop,...
# Optional API keys
# Default: none
#BTCEXP_GANALYTICS_TRACKING=UA-XXXX-X
#BTCEXP_SENTRY_URL=https://00000fffffff@sentry.io/XXXX
#BTCEXP_IPSTACK_APIKEY=000000fffffaaaaa
#BTCEXP_MAPBOX_APIKEY=000000fffffaaaaa
# Optional value for a directory for filesystem caching
# Default: ./cache
#BTCEXP_FILESYSTEM_CACHE_DIR=./cache
# Optional analytics
#BTCEXP_PLAUSIBLE_ANALYTICS_DOMAIN=domain.com
#BTCEXP_PLAUSIBLE_ANALYTICS_SCRIPT_URL=https://url-to/plausible.js
# Optional value for "max_old_space_size"
# Default: 1024
#BTCEXP_OLD_SPACE_MAX_SIZE=2048
# The number of recent blocks to search for transactions when txindex is disabled
#BTCEXP_NOTXINDEX_SEARCH_DEPTH=3
# UI Theme
# Default: dark
#BTCEXP_UI_THEME=(dark|light)
# Set the number of recent blocks shown on the homepage.
# For slow devices reduce this number.
# Default: 10
#BTCEXP_UI_HOME_PAGE_LATEST_BLOCKS_COUNT=10
# Set the number of blocks per page on the browse-blocks page.
# For slow devices reduce this number.
# Default: 50
#BTCEXP_UI_BLOCKS_PAGE_BLOCK_COUNT=50
To Reproduce
Steps to reproduce the behavior:
Start parity-bitcoin
cd to btc-rpc-explorer
npm i
npm start
Screenshots or Log Output
btcexp:app Starting BTC RPC Explorer, v3.1.1 (commit: 'c706bbc29c', date: 2021-06-16) at http://127.0.0.1:3002/ +22ms
btcexp:app Connecting to RPC node at 127.0.0.1:8332 +0ms
btcexp:app Verifying RPC connection... +3ms
btcexp:rpc RPC: getnetworkinfo +0ms
btcexp:rpc RPC: getblockchaininfo +1ms
btcexp:app Loading mining pools config +1ms
simple-git [GitExecutor] [SPAWN] exitCode=0 event=close rejection=undefined +10ms
simple-git:task:log:1 [SPAWN] exitCode=0 event=close rejection=undefined +10ms
{"name":"bitcoin-core","hostname":"MU00152739X","pid":37232,"level":20,"request":{"headers":{"host":"127.0.0.1:8332","authorization":"Basic ******","content-length":60},"id":"2b75dde0-d6c0-417d-8245-0c93b68d1d84","method":"POST","type":"request","uri":"http://127.0.0.1:8332/","body":"{\"id\":\"1624169859181\",\"method\":\"getnetworkinfo\",\"params\":[]}"},"msg":"Making request 2b75dde0-d6c0-417d-8245-0c93b68d1d84 to POST http://127.0.0.1:8332/","time":"2021-06-20T06:17:39.190Z","v":0}
{"name":"bitcoin-core","hostname":"MU00152739X","pid":37232,"level":20,"request":{"headers":{"host":"127.0.0.1:8332","authorization":"Basic ******","content-length":63},"id":"d7db81ac-e449-4437-abae-11030e273a8e","method":"POST","type":"request","uri":"http://127.0.0.1:8332/","body":"{\"id\":\"1624169859184\",\"method\":\"getblockchaininfo\",\"params\":[]}"},"msg":"Making request d7db81ac-e449-4437-abae-11030e273a8e to POST http://127.0.0.1:8332/","time":"2021-06-20T06:17:39.192Z","v":0}
undefined:1
Supplied content type is not allowed. Content-Type: application/json is required
^
SyntaxError: Unexpected token S in JSON at position 0
at JSON.parse (<anonymous>)
at obfuscateResponse (/Users/rhan0013/Projects/randchain-dev/randchain-explorer/node_modules/btc-rpc-client/dist/src/logging/request-obfuscator.js:60:23)
at obfuscate (/Users/rhan0013/Projects/randchain-dev/randchain-explorer/node_modules/btc-rpc-client/dist/src/logging/request-obfuscator.js:142:3)
at /Users/rhan0013/Projects/randchain-dev/randchain-explorer/node_modules/btc-rpc-client/dist/src/logging/request-logger.js:24:36
at Request.<anonymous> (/Users/rhan0013/Projects/randchain-dev/randchain-explorer/node_modules/@uphold/request-logger/src/index.js:33:9)
at Request.emit (events.js:327:22)
at Request.<anonymous> (/Users/rhan0013/Projects/randchain-dev/randchain-explorer/node_modules/request/request.js:1154:10)
at Request.emit (events.js:315:20)
at IncomingMessage.<anonymous> (/Users/rhan0013/Projects/randchain-dev/randchain-explorer/node_modules/request/request.js:1076:12)
at Object.onceWrapper (events.js:421:28)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Sorry, I'm really not sure about this. I don't run any non-bitcoin projects and can't support any non-bitcoin projects, but I wish you luck getting to the bottom of this issue.
Describe the bug
I'm currently developing an explorer for my own blockchain based on this project. The blockchain is developed upon
parity-bitcoin
. When I start the explorer usingnpm start
, the error occurs:Supplied content type is not allowed. Content-Type: application/json is required
.I tested the API over Postman, and indeed the request goes correctly if I add
Content-Type: application/json
to the header. The debugging log showed that the request indeed does not include the headerContent-Type: application/json
, so I tried to manually add it in the code (at every place withnew bitcoinCore()
). However, the error remains. I'm wondering what is the right way of doing this?Environment (please complete the following information):
Configuration file content
To Reproduce
Steps to reproduce the behavior:
parity-bitcoin
cd
tobtc-rpc-explorer
npm i
npm start
Screenshots or Log Output
Additional context