GithubHelp home page GithubHelp logo

jzambranoavvy / gateway Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hypermedialabs/gateway

0.0 0.0 0.0 32 KB

Home Page: https://hy-gateway-prod-test.vercel.app

Shell 1.83% JavaScript 98.17%

gateway's Introduction

Hypermedia Gateway

X (formerly Twitter) Follow

Welcome to Hypermedia Gateway, this is a server that allows you to upload files to the Hypermedia API.

  • Why use Hypermedia Gateway?
  • What contains?
  • How it is works?
  • Installation
    • Using Vercel (Recommended)
    • Self hosted

Why use Hypermedia Gateway?

The main reason to use Hypermedia Gateway is to avoid exposing your API key to your clients, this is a security measure to avoid that your API key is exposed to the public.

Another reason is to avoid CORS problems, Hypermedia Gateway allows you to set up a list of allowed domains to get the upload information. This is a security measure to avoid that anyone can push files to your Hypermedia account.

We recommend using Hypermedia Gateway in PRODUCTION environments.

If you are using Hypermedia Gateway in development environments, please be sure to add localhost:[PORT] to the list of allowed domains.

What contains?

The repo contains 2 endpoints: /api/upload-information and /api/upload-completed.

  • upload-information: This endpoint is used to get the upload information from the Hypermedia API, this is the information that you need to upload files using the TUS Protocol.

  • upload-completed: This endpoint is used to notify to the Hypermedia API that the upload has been completed, this is necessary to save the file already uploaded into our database and link it with your account.

How it is works?

Here you can see a diagram of how it works:

sequenceDiagram
Client Uploader ->> Hypermedia Gateway: HEAD /hypermedia-gateway-endpoint <br/> \ REQUEST HEADERS: {origin: client-uploader.domain.com}
Note left of Client Uploader: This is the request <br/> to get the upload <br/> information
Hypermedia Gateway->>Client Uploader: Headers: access-control-allow-origin: <br/> client-uploader.domain.com
Note right of Hypermedia Gateway: Gateway allows the request <br/> because we need to set up <br/> a .env file <br/> into the project with the <br/> ALLOWED_DOMAINS variable <br/> with client-uploader.domain.com <br/> as a value.
Note left of Client Uploader: Browser verifies <br/> we are client-uploader.domain.com <br/> and allows the request
Hypermedia Gateway ->> Hypermedia API: Get upload information using your <br/> HYPERMEDIA_API_KEY into your .env file in your <br/> Hypermedia Gateway project
Hypermedia API ->> Hypermedia Gateway: Returns the upload information
Hypermedia Gateway ->> Client Uploader: Returns the upload information
Loading

Installation

First of all we need to do a Fork of this repo into your own github account, this is necessary to deploy the server using Vercel. If you don't want to use Vercel, you can deploy the server using any other service.

How to fork this repo and get updates from the original repo?

  1. Fork this repo into your own github account
  2. Clone your forked repo into your local machine
  3. Add the original repo as a remote repo
    git remote add upstream
  4. Verify that the original repo has been added as a remote repo
    git remote -v
  5. Fetch the original repo
    git fetch upstream
  6. Merge the original repo into your forked repo
    git merge upstream/main
  7. Push the changes to your forked repo
    git push origin main
  8. Verify that the changes have been pushed to your forked repo
    git log
  9. Now you can deploy your forked repo using Vercel

Using Vercel (Recommended)

For this installation we will have 2 ways to do it, the first one with a button to do it directly using the vercel dashboard or the second one using the Vercel CLI.

  1. Click on the following button: Deploy with Vercel

  2. Select your forked repo enter image description here

  3. Finish the whole deployment process in Vercel and then copy the public url from here enter image description here.

This is the URL that you need to paste into @hypermedialabs/uploader.

Environment Variables

After deploying the server using Vercel, you need to set up the following environment variables:

Go to Settings -> Environment Variables Variables and add the variables that we mentioned before.

enter image description here

Please do not add localhost domains in production environments.

Returning to the client

At this point your server is ready to return to your client the necessary information to upload files using the TUS Protocol.

Now just go to your client and using the @hypermedialabs/uploader library paste the URL generated by vercel into the code.

Self hosted

Self host is allowed but make sure to follow the next steps:

  1. Clone this repo into your local machine
  2. Install the dependencies
    npm install
  3. Create a .env file in the root of the project and add the variables that we mentioned before.

gateway's People

Contributors

jzambrano12 avatar

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.