如何在Stampery API.JS文件中设置API密钥

我正在努力设立St。。 我无法弄清楚在这个API.JS文件中设置stringAPI密钥的位置。 该文件说,将STAMPERY_TOKEN设置为API密钥不知道如何做到这一点。 任何帮助,将不胜感激。

Stampery的链接是https://github.com/stampery/office 。

'use strict'; const express = require('express'); const router = express.Router(); const bodyParser = require('body-parser') const Stampery = require('stampery'); const development = process.env.NODE_ENV !== 'production'; const stamperyToken = process.env.STAMPERY_TOKEN; var proofsDict = {} if (!stamperyToken) { console.error('Environment variable STAMPERY_TOKEN must be set before running!'); process.exit(-1); } //var stampery = new Stampery(process.env.STAMPERY_TOKEN, development ? 'beta' : false); // For now, always use production Stampery API due to not making it work against beta. var stampery = new Stampery(process.env.STAMPERY_TOKEN); router.use(bodyParser.json()); router.post('/stamp', function (req, res) { var hash = req.body.hash; // Throw error 400 if no hash if (!hash) return res.status(400).send({error: 'No Hash Specified'}); // Transform hash to upper case (Stampery backend preferes them this way) hash = hash.toUpperCase() // Throw error 422 if hash is malformed var re = /^[A-F0-9]{64}$/; if (!(re.test(hash))) return res.status(422).send({error: 'Malformed Hash'}); stampery.stamp(hash, function(err, receipt) { if (err) res.status(503).send({error: err}); else res.send({result: receipt.id, error: null}); }); }); router.get('/proofs/:hash', function (req, res) { var hash = req.params.hash; stampery.getByHash(hash, function(err, receipts) { if (err) res.status(503).send({error: err}); else if (receipts.length > 0) res.send({result: receipts[0], error: null}); else res.status(200).send({error: 'Oops! This email has not yet been attested by any blockchain.'}); }); }); module.exports = router; 

我在Azure网站中添加了以下内容。 这应该足够了: 在这里输入图像描述

在启动服务器之前,您需要设置STAMPERY_TOKEN环境。

你可以这样做,例如(在Windows中) set STAMPERY_TOKEN=your-token&& node app.js

有两种方法可以将其添加到环境中(对于Ubuntu)。

  1. 添加到bashrc文件。 喜欢:

    导出STAMPERY_TOKEN =“您的托运”

  2. 在运行服务器之前传递这些参数。 喜欢:

    STAMPERY_TOKEN = YOUR-TOKEN节点server.js

要访问这个variables,你可以通过:

的console.log(process.env [ “STAMPERY_TOKEN”]);