Skip to content

Commit

Permalink
add cors
Browse files Browse the repository at this point in the history
  • Loading branch information
gandlafbtc committed Feb 14, 2023
1 parent aa34ff5 commit 03d7e5c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "ISC",
"dependencies": {
"@gandlaf21/cashu-tools": "^0.1.2",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"express-rate-limit": "^6.7.0"
Expand Down
8 changes: 5 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require('dotenv').config()
const { CashuMint, CashuWallet, getEncodedProofs } = require("@gandlaf21/cashu-ts")
const { Faucet } = require ("@gandlaf21/cashu-tools")
const rateLimit = require('express-rate-limit')
const cors = require('cors');

const express = require('express')
const app = express()
Expand All @@ -11,13 +12,14 @@ const port = process.env.PORT
let faucet

const limiter = rateLimit({
windowMs: 15 * 1000, // 15 seconds
windowMs: 15 * 1000, // 15 seconds
max: 5, // Limit each IP to 100 requests per `window` (here, per 15 minutes)
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
})

app.use(limiter)
app.use(cors());

app.get('/', (req, res) => {
let responseString ="Token has already been claimed! waiting for next token..."
Expand All @@ -31,6 +33,7 @@ app.get('/', (req, res) => {
app.get('/charge', async (req, res) => {
const token = req.query.token
const message = await faucet.charge(token)
console.log("all Tokens:", getEncodedProofs(balance ,[{url:process.env.MINT_URL, keysets: [...new Set(faucet.currentToken.map(t=>t.id))]}]))
res.send({message})
})

Expand All @@ -40,7 +43,6 @@ app.listen(port, async () => {
const cashuWallet = new CashuWallet(keys, cashuMint)
faucet = new Faucet(cashuWallet, process.env.FAUCET_INTERVAL, process.env.SATS_PER_INTERVAL)
await faucet.start()

console.log(`Example app listening on port ${port}`)
console.log(`Example app listening on port ${port}`)
})

0 comments on commit 03d7e5c

Please sign in to comment.