GithubHelp home page GithubHelp logo

rhildred / cors-proxy2 Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 253 KB

simplified to run as a cloudflare pages function or express app

Home Page: https://rhildred.github.io/cors-proxy2

License: MIT License

JavaScript 100.00%
cloudflare-pages cors functions github http-proxy proxy isomorphic-git stackblitz

cors-proxy2's Introduction

cors-proxy2

Cloudflare worker to run with Stackblitz.com and github.com.

To use:

npm install --save-dev @rhildred/cors-proxy2

put the url in the path. For instance:

const res = await request(app).get("/corsproxy/github.com/diy-pwa/diy-pwa/archive/refs/heads/main.zip");

Consume in cloudflare pages function. For instance in functions/corsproxy/[[corsproxy]].js:

import { CorsProxyResponse } from '@rhildred/cors-proxy2';

export async function onRequest(context){
    context.env.url = context.request.url.replace(/^.*corsproxy/, "https:/");
    return CorsProxyResponse.fetch(context.request, context.env);
}

or as a worker I think. You will need to use a bundler.

import { CorsProxyResponse } from '@rhildred/cors-proxy2';
export default { 
    fetch(req, env){
        env.url = req.url.replace(/^.*corsproxy/, "https:/");
        return CorsProxyResponse.fetch(req, env);
    }
};

This code is based on the cors-proxy code from isomorphic-git. It is refactored to be exposed as a cloudflare worker or pages function.

I am super excited about the tests for this cloudflare pages function/worker. Particularly this one:

import { describe, it, expect } from 'vitest';
import request from 'supertest';
import createApp from './expressFixture.js';
import git from 'isomorphic-git';
import fs from 'fs';
import http from 'isomorphic-git/http/web';


...

    it("clones a git repo", async ()=>{
        const app = createApp();
        const server = await app.listen(8080);
        await git.clone({
            corsProxy: 'http://127.0.0.1:8080/corsproxy',
            url: 'https://github.com/rhildred/cors-proxy2',
            ref: 'main',
            singleBranch: true,
            depth: 10,
            dir: 'test2',
            fs: fs,
            http
        });  
        await server.close();
        expect(true).toBe(true);

    }, 20000);

It is exciting to me for 2 reasons. It is self contained. It consumes the actual proxy using the main use case. To use with isomorphic git.

I am consuming the cloudflare pages function in diy-pwa and git-pwa. These projects are for a stackblitz development environment for sales engineers to make progressive web apps. The pwa is for hosting .svg configuration models and complements for business to business products.

cors-proxy2's People

Contributors

billiegoose avatar deltaevo avatar fossprime avatar hisener avatar jcubic avatar rhildred avatar richard-hildred avatar tiagobento avatar

Stargazers

 avatar

Watchers

 avatar  avatar

cors-proxy2's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.