Giter VIP home page Giter VIP logo

hybrid-app-example's Introduction

Building a Hybrid App

This guide will walk you through the process of building a Hybrid App which allows a user to generate images from a Designer Extension using OpenAI’s Dall-E service and add them to a site’s assets. A Hybrid App uses the capabilities of both a Data Client App and a Designer Extension. Please read through our documentation to familiarize yourself with these concepts.

What we're building

hybrid app walktrhough

We're diving into the capabilities of a Webflow App with an example that showcases Designer Extensions and Data Clients.

You'll set up an app named "Devflow Party". Once installed, this app integrates a Designer Extension into the Webflow canvas, prompting users to generate images via OpenAI. Following this, it employs Webflow's REST APIs to automatically integrate the chosen images into a Webflow site.

🏃🏽‍♂️ Jump to the tutorial!

App Structure

While these two App building blocks work closely together, they are hosted and managed very differently in a Hybrid App.
Hybrid Apps are split into two different areas of functionality:

This example app is contained within two separate folders.

  • designer-extension
  • data-client

Communicating between Designer Extensions and Data Clients

diagram of how apps communicate

This example implements a lightweight API to pass data between the Designer Extension and Data Client. The Data Client makes API calls to the Webflow Data API and serves that data to your Extension. While it's possible to call third-party APIs directly from the Designer Extension, we’ve decided to call APIs from the Data Client, so that we're keeping all secrets contained on our backend.

Calling Webflow APIs

Adding Images to Site Assets

Devflow Party, our Data Client app, spins up a server with helpers to handle OAuth as well as Webflow Data API requests.

Once a user has used the Designer Extension to generate the desired images, our Data Client will need to add them to the site’s Assets. The user will select the images they wish to add, and the Devflow Extension will send a request to the Devflow service, telling the service to upload the assets.

Once the service receives an upload request, it will temporarily cache the image to disk, then upload the image to S3 and apply it to the site’s Assets list.

Walkthrough

Prerequisites

  • A Webflow workspace and site for development and testing
  • A Webflow App with the Data Client and Designer Extension Building Blocks enabled
  • The ID, Secret, and Client URL from your Webflow App
  • A free OpenAI account with an API Key
  • Node.js 16.20 or later
  • Familiarity building single-page applications

Step 1: Setting up your development environment

First, install the Webflow CLI: npm i @webflow/webflow-cli -g

We're going to use GitHub codespaces as our development environment, to tak advantage of it's built in port forwarding, but please feel free to follow along developing locally.

  1. Clone the example repo to your development environment. Navigate the Hybrid-App-Example repo. Select the code button and open the repo in a GitHub codespace or, if you'd like, clone the repo to your local environment.

  2. Find your redirect URI. If you're using GitHub Codespaces, you'll want to get the URI of the forwarded port to use as the redirect URL for our Data Client app. To do this, copy the Github Codespaces URL in the address bar of your browser. Then add a -3001.app to the link as shown:

    • Orignial URL: https://curly-train-5rg69pjrrp9f4v6v.github.dev
    • Modified URL: https://curly-train-5rg69pjrrp9f4v6v-3001.app.github.dev

Note

If you're hosting your app locally, copy the URI for your port. Please note, redirect URIs for data clients are required to use https. You can use tools like NGROK to expose your local server over https or setup your own security certificate for local development.

  1. Modify your App's redirect URI. Navigate to the "App Development" section of your Workspace Settings and select the Edit App button. Select the "Building Blocks" panel. In the "Data Client" section, replace the redirect URI with the your local development URI. Click the Save app button.

Paste your redirect URI in the Yellow Box

  1. Configure your environment variables. In your IDE, copy the .env.local.example file and name it .env.local. Replace the variables with your own.

Note

There are 2 .env.local.example files. You must update the environment variables for both. "NEXT_PUBLIC_BACKEND_URL" should be set to the public URL of your Data Client.

  1. Run your Hybrid App! Now it's time to run your App! Open your terminal and navigate to your project folder. Enter the following command: npm run dev. This will install the dependencies for your Data Client and Designer Extension, and then run them on their default ports 3001 and 1337, respectively.

Step 2: Authorize your Data Client

  1. Open the Data Client in your browser. Open the link to your forwarded port. You should see a login screen. Click the login button. Screenshot of the login experience for the DevFlow Party App

Important

If you're using Github Codespaces, your ports will already be forwarded. Be sure to set your port visibility to public, so that you'll be able to see your App running in Webflow.

  1. Authorize App to your development workspace. Because we're working with a Data Client that will access Webflow's REST API we'll need to authorize our App to make changes on behalf of a user. You are only able to authorize an App to sites within a single workspace, or one completee workspace. Be sure to select the Workspace where you created your App. Screenshot of the Authorization Screen Once authorized, you'll be redirected to a success screen in your Data Client.

Step 3: Open your Designer Extension in Webflow

  1. Open your test Site in your Development Workspace. Navigate to your Development Workspace and open a test site.

  2. Select your App from the Apps Panel. In the left toolbar, select the Apps panel. Navigate to your App, and select it to see it's details.

  3. Replace your Development URL. Similar to how we changed our redirect URI to the forwarded URL for port 3001, change your Development URL to point to the forwarded URL for port 1337.

designer extension details

  1. Launch your App in the Designer! 🚀 Select the Launch development App button.

launched app!

Step 4: Generate images via the Designer Extension.

  1. Enter your image prompt. Our App is designed to generate images from a prompt using OpenAI's DALL-E API. To generate images, enter a prompt in the input section.

  2. Select your image size and quantity.

  3. Click the Generate button to create new images. We're sending our prompt to our DevFlow Party App, which then makes an authenticated API call to DALL-E to generate the images. DevFlow party then saves the images to our sites's Assets via the REST API.

Important

Refresh your browser! Until we make some changes to the designer, you'll need to refersh your browser to see changes from the API take effect. 🙇🏾‍♀️

  1. Open your Apps pane to see your new Images. Refresh your browser, and then navigate to the Assets panel in the left toolbar. You'll now see your images, which are ready to use in the designer!

assets panel

Step 5. Pat yourself on the back!

You did it!

hybrid-app-example's People

Contributors

roach avatar rodneyu215 avatar victoriaplummer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hybrid-app-example's Issues

Error: Argument 'client_id' is required but was not present

image image

I have my app running on Github codespaces and I set the app url from there as my redirect uri in the data client. It gives me this error. Am I doing something wrong?

For context, I want to integrate an hybrid app via oauth2.0

In regards to the same, I have one more question being, where I can I access a reference ( i.e client id ) to the user installing this app, when they redirect to my custom app for authorization?

What are server.key and server.crt?

When I try to run the devflow-party-data-client via "npm run dev" it first complains that it cannot find server.key. And if I create an empty file of said name, it complains that it cannot find server.cert. It is unclear what data is supposed to live in these files and where that data should come from: generated? sourced from somewhere? what format? None of the READMEs provide information either and they assume that "npm run dev" succeeds as is, which is not the case.

Adding sites

Once you get both apps running and go to localhost/1337, then give the openaitoken, how do you add sites? I do not see any sites. and when I authorize through the app on localhost:3001, nothing happens.

The example could do with a bit more guidance on the elements and how they interact with the new API!

Wrong redirect after log in

After logining in app anyway redirects me to login page. I`ve already added .env.local file which contains CLIENT_ID and CLIENT_SECRET. What am I doing wrong?

Where is the .env.example file?

In the README you mention:
"Configure your environment variables. In your IDE, copy the .env.example file and name it .env.local. Replace the variables with your own."

I don't see the .env.example file anywhere?

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.