Skip to content

Instantly share code, notes, and snippets.

@isaacs
Last active February 6, 2023 22:55
Show Gist options
  • Save isaacs/084d4e0755e2463cded4ab5288b8ae1e to your computer and use it in GitHub Desktop.
Save isaacs/084d4e0755e2463cded4ab5288b8ae1e to your computer and use it in GitHub Desktop.
const apiKey = {{ stripe test private key goes here }}
const html = `
<!doctype html>
<html>
<head>
<script type="module">
import { Tier } from 'https://unpkg.com/tier@5.0.3/dist/mjs/client.js'
const tier = new Tier({
apiKey: ${JSON.stringify(apiKey)},
baseURL: 'https://api.tier.run',
})
tier.whoami().then(result => {
document.body.innerHTML = '<pre>' + JSON.stringify(result) + '</pre>'
}).catch(er => {
document.body.innerHTML = '<pre>' + String(er) + '\\n(probably cors related)</pre>'
})
</script>
<body>fetching whoami...</body>
`
require('http').createServer((_req, res) => {
res.setHeader('content-type', 'text/html')
res.end(html)
}).listen(8080, () => console.log('http://localhost:8080/'))
@isaacs
Copy link
Author

isaacs commented Feb 6, 2023

if api.tier.run had CORS setup to allow localhost:8080, this would work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment