This is an automated email from the ASF dual-hosted git repository.

urfree pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-site.git


The following commit(s) were added to refs/heads/main by this push:
     new cfc6f4654ad fix rest api page crash (#439)
cfc6f4654ad is described below

commit cfc6f4654adc42b333af70df9d1ed41da3d62ea8
Author: Li Li <[email protected]>
AuthorDate: Wed Mar 1 10:44:57 2023 +0800

    fix rest api page crash (#439)
---
 src/components/RestApi.js |  7 +------
 src/utils/index.js        | 10 +++++++---
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/components/RestApi.js b/src/components/RestApi.js
index ad648344f87..fe59cb272fc 100644
--- a/src/components/RestApi.js
+++ b/src/components/RestApi.js
@@ -1,4 +1,4 @@
-const React = require("react");
+import * as React from "react";
 import Layout from "@theme/Layout";
 import { getVersion, getApiVersion } from "../utils/index.js";
 
@@ -102,11 +102,6 @@ class RestApi extends React.Component {
       "https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js";
     );
     const script = document.querySelector(".container script");
-    console.log(
-      "script: ",
-      script,
-      "/swagger/" + version + "/" + apiversion + "/swagger.json"
-    );
     wrapper.insertBefore(redoc, script);
     wrapper.insertBefore(redocLink, script);
   }
diff --git a/src/utils/index.js b/src/utils/index.js
index 7232243e5da..e9a0eb156d3 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -54,10 +54,14 @@ export function setVersion(version) {
 }
 
 export function getVersion() {
-  if (/version=(\d+\.?\x?)+/.test(location.href)) {
-    return location.href.match(/version=(\d+\.?\x?)+/)[0];
+  try {
+    if (/version=(\d+\.?\x?)+/.test(location.href)) {
+      return location.href.match(/version=((\d+\.?\x?)+)/)[1];
+    }
+  } catch (error) {
+    console.error(error)
+    return "master";
   }
-  return "master";
 }
 
 export function getApiVersion(anchor) {

Reply via email to