Skip to content

Commit

Permalink
localstripe.js: Fix LOCALSTRIPE_BASE_API on dynamical load
Browse files Browse the repository at this point in the history
This continues commit c89bb15 "API: Allow serving localstripe API from a
custom URL" by simplifying the way to get localstripe server URL, and
also fixes the case when `localstripe.js` is loaded dynamically (in this
case, `document.getElementsByTagName('script')` references the wrong
element: the calling/parent `<script>`) like this:

    let script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'http://localhost:8420/js.stripe.com/v3/';
    document.head.appendChild(script);
  • Loading branch information
adrienverge committed Sep 17, 2024
1 parent 39c1ebb commit d446648
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions localstripe/localstripe-v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

// First, get the URL base from which this script is pulled:
const LOCALSTRIPE_BASE_API = (function () {
const scripts = document.getElementsByTagName('script');
const src = scripts[scripts.length - 1].src;
const src = document.currentScript.src;
if (src.match(/\/js\.stripe\.com\/v3\/$/)) {
return src.replace(/\/js\.stripe\.com\/v3\/$/, '');
} else {
Expand Down

0 comments on commit d446648

Please sign in to comment.