mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-07-21 12:57:38 +01:00
e3b77ec1f2
* Update Az CLI to use new secrets. * Add test step for Az login * Remove test step. Fix up account names in test code. * Fix the account prefix env. variable. * Fix it in the CI config as well. * Try to fix the CI config for some tests * Clean up access tokens for NoSQL. * Disable most tests while sorting out account setup. Add debug tracing. * Comment out most tests. * Set RG Name var in CI config. * Fix up tenant id. * Enable other API tests * e-enable more tests. * Re-enable remaining tests. * Remove all of the test.skip() calls. * Remove debug traces. * Remove function to retrieve SQL RBAC token, this is handled by the CI config now. * Fix rbac token detection for table and resource token tests. * Minor cleanup and fixing the cleanup config. * Preview site and storage changes. Cleanup script changes. * Clean up before PR. * Fix resource group name in test results email.
83 lines
2.4 KiB
JavaScript
83 lines
2.4 KiB
JavaScript
const express = require("express");
|
|
const { createProxyMiddleware } = require("http-proxy-middleware");
|
|
const port = process.env.PORT || 3000;
|
|
const fetch = require("node-fetch");
|
|
|
|
const backendEndpoint = "https://cdb-ms-mpac-pbe.cosmos.azure.com";
|
|
const previewSiteEndpoint = "https://dataexplorer-preview.azurewebsites.net";
|
|
const previewStorageWebsiteEndpoint = "_REPLACE_STORAGE_WEBSITE_ENDPOINT_";
|
|
const githubApiUrl = "https://api.github.com/repos/Azure/cosmos-explorer";
|
|
const azurePortalMpacEndpoint = "https://ms.portal.azure.com/";
|
|
|
|
const api = createProxyMiddleware({
|
|
target: backendEndpoint,
|
|
changeOrigin: true,
|
|
logLevel: "debug",
|
|
bypass: (req, res) => {
|
|
if (req.method === "OPTIONS") {
|
|
res.statusCode = 200;
|
|
res.send();
|
|
}
|
|
},
|
|
});
|
|
|
|
const proxy = createProxyMiddleware({
|
|
target: backendEndpoint,
|
|
changeOrigin: true,
|
|
secure: false,
|
|
logLevel: "debug",
|
|
pathRewrite: { "^/proxy": "" },
|
|
router: (req) => {
|
|
let newTarget = req.headers["x-ms-proxy-target"];
|
|
return newTarget;
|
|
},
|
|
});
|
|
|
|
const commit = createProxyMiddleware({
|
|
target: previewStorageWebsiteEndpoint,
|
|
changeOrigin: true,
|
|
secure: false,
|
|
logLevel: "debug",
|
|
pathRewrite: { "^/commit": "/" },
|
|
});
|
|
|
|
const app = express();
|
|
|
|
app.use("/api", api);
|
|
app.use("/proxy", proxy);
|
|
app.use("/commit", commit);
|
|
app.get("/pull/:pr", (req, res) => {
|
|
const pr = req.params.pr;
|
|
if (!/^\d+$/.test(pr)) {
|
|
return res.status(400).send("Invalid pull request number");
|
|
}
|
|
const [, query] = req.originalUrl.split("?");
|
|
const search = new URLSearchParams(query);
|
|
|
|
fetch(`${githubApiUrl}/pulls/${pr}`)
|
|
.then((response) => response.json())
|
|
.then(({ head: { sha } }) => {
|
|
const explorer = new URL(`${previewSiteEndpoint}/commit/${sha}/explorer.html`);
|
|
explorer.search = search.toString();
|
|
|
|
const portal = new URL(azurePortalMpacEndpoint);
|
|
portal.searchParams.set("dataExplorerSource", explorer.href);
|
|
|
|
return res.redirect(portal.href);
|
|
})
|
|
.catch(() => res.sendStatus(500));
|
|
});
|
|
app.get("/", (req, res) => {
|
|
fetch(`${githubApiUrl}/branches/master`)
|
|
.then((response) => response.json())
|
|
.then(({ commit: { sha } }) => {
|
|
const explorer = new URL(`${previewSiteEndpoint}/commit/${sha}/hostedExplorer.html`);
|
|
return res.redirect(explorer.href);
|
|
})
|
|
.catch(() => res.sendStatus(500));
|
|
});
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Example app listening on port: ${port}`);
|
|
});
|