Skip to content

Goodbye Unirun - 校园跑助手网页版🏃‍♂️

Notifications You must be signed in to change notification settings

Yanyaoli/byerun-web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 

Repository files navigation

Byerun

Byerun web

Goodbye Unirun - Campus Running Assistant Web Version🏃‍♂️

Supported Maps

School List
Chengdu University of Information Technology
Chengdu University of Traditional Chinese Medicine
Nanchong Health School of Sichuan Province
...

Demo

Deployment Platform Byerun Unirun
Cloudflare Byerun Unirun
Vercel Byerun Unirun

Build

Enter the project folder:

cd app

Install dependencies:

npm install-all

Run for development:

npm run start

Build for production:

npm run build

Server

Supports deployment of the server backend on Vercel and Cloudflare.

Function: Avoid cross-origin restrictions of the source server.

graph TD;

    classDef process fill:#E5F6FF,stroke:#73A6FF,stroke-width:2px;

    classDef error fill:#FFEBEB,stroke:#E68994,stroke-width:2px;



    A([ByerunWeb]):::process -->|Direct Request| U([UnirunAPI]):::process

    U --> |Cross - Origin Restriction| E([Request Failed]):::error

    A -->|Request Forwarded | C([Cloudflare / Vercel]):::process

    C --> U

    U --> C

    C --> |Response Returned| A
Loading

Cloudflare Worker

export default {
  async fetch(request, env) {
    if (request.method === 'OPTIONS') {
      return new Response(null, {
        status: 200,
        headers: {
          'Access-Control-Allow-Origin': '*',
          'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
          'Access-Control-Allow-Headers': '*'
        }
      });
    } else {
      return handleRequest(request, env);
    }
  }
};

async function handleRequest(request, env) {
  const url = new URL(request.url);
  const backendUrl = 'https://run-lb.tanmasports.com/v1' + url.pathname + url.search;

  const newHeaders = new Headers(request.headers);
  newHeaders.delete('Host');

  const init = {
    method: request.method,
    headers: newHeaders,
    body: request.method === 'GET' ? null : await request.clone().text()
  };

  const response = await fetch(backendUrl, init);

  const responseHeaders = new Headers(response.headers);
  responseHeaders.set('Access-Control-Allow-Origin', '*');
  responseHeaders.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
  responseHeaders.set('Access-Control-Allow-Headers', '*');

  const body = await response.text();

  return new Response(body, {
    status: response.status,
    headers: responseHeaders
  });
}

Disclaimer

This project is for learning and research purposes only and shall not be used for any commercial or illegal purposes. If you need to experience the full functionality, please use the official App.

Any direct or indirect risk damage of any nature caused by the use of this project shall be borne by the user, and the developer shall not bear any responsibility for the user's illegal behavior.

If the official believes that this project is inappropriate, please contact us through Issues and we will modify or remove it.

Acknowledgements

@msojocs/AutoRun

License

Byerun is released under the CC BY-NC License, Version 4.0.