Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

isogit-cors-proxy

node v18.11.0
version: 2.1.0
endpointsharetweet
const express = require('express') const corsProxy = require('@isomorphic-git/cors-proxy/middleware.js') const service = require('@isomorphic-git/cors-proxy') const port = 3000 const app = express() // The origin on Firefox is different to Chrome const stackblitzCors = (req, res, next) => { const orgy = req.header('Origin') const wcTld = '.staticblitz.com' const browserTld = '.webcontainer.io' // console.log(orgy) if (orgy && (orgy.endsWith(wcTld) || orgy.endsWith(browserTld))) { const myProxy = corsProxy({ origin: req.origin }) myProxy(req, res, next) } else if (orgy === undefined) { const bareMetalProxy = corsProxy({ origin: req.origin }) bareMetalProxy(req, res, next) } else { console.log(`Origin header is: ${orgy}`) next() } } app.use(stackblitzCors) // Alternatively, app.use(service) app.get('/', (_req, res, _next) => { res.send('Hello StackBlitz!') }) const rkUrl = process.env.RUNKIT_ENDPOINT_URL console.log(`You can test by running: $ npx isomorphic-git clone --corsProxy="RUNKIT_ENDPOINT_URL" --url="https://github.com/isomorphic-git/isomorphic-git.git" Redirects are not supported, so you'll need the root endpoint url... not the one that ends with a path and starts with runkit.io, but the one that ends with runkit.sh. You can find out what your endpoint url is by visiting ${rkUrl} It should look something like "https://untitled-123abc.runkit.sh" DO NOT add a forward slash at the end! `)
app.listen(port, () => { console.log(`Example app listening at ${rkUrl}`) })
Loading…

no comments

    sign in to comment