datastaxdevs / workshop-social-media-tiktok

A simple Tik Tok clone running on AstraDB that leverages the Document API.
https://astra.datastax.com/register
Apache License 2.0
62 stars 65 forks source link
cassandra cassandra-database netlify

Astra DB TikTok Clone Workshop

Gitpod ready-to-code License Apache2 Discord

⏲️ Duration : 2 hours

πŸŽ“ Level Beginner to Intermediate

A simple Tik-Tok clone running on Astra DB that leverages the Document API. You can see the Demo here

image

πŸ”– Accessing HANDS-ON

πŸ“‹ Table of contents

Housekeeping

1 - Objectives

2 - Frequently asked questions

1️⃣ Can I run this workshop on my computer?

There is nothing preventing you from running the workshop on your own machine. If you do so, you will need the following:

  1. git installed on your local system
  2. [node 15 and npm 7 or later](https://www.whitesourcesoftware.com/free-developer-tools/blog/update-node-js/)

In this readme, we try to provide instructions for local development as well - but keep in mind that the main focus is development on Gitpod, hence we can't guarantee live support about local development in order to keep on track with the schedule. However, we will do our best to give you the info you need to succeed.

2️⃣ What other prerequisites are there?
  • You will need an Github account
  • You will need an Astra account don't worry, we'll work through that in the workshop
  • You will need enough real estate on screen, we will ask you to open a few windows and it would not fit on mobiles (tablets should be OK)

3️⃣ Do I need to pay for anything for this workshop?
No. All tools and services we provide here are FREE. FREE not only during the session but also after.

4️⃣ Will I get a certificate if I attend this workshop?
Attending the session is not enough. You need to complete the homework detailed below and you will get a nice badge that you can share on linkedin or anywhere else *(open badge specification)*

3 - Materials for the Session

It doesn't matter if you join our workshop live or you prefer to do at your own pace, we have you covered. In this repository, you'll find everything you need for this workshop:

4 - Homework

Don't forget to complete your work and get your verified skill badge! Finish and submit your homework!

  1. Complete the practice steps from this repository as described below. Take a screenshot and show us your deployed production TikTok clone up in Netlify.
  2. (Optional extra credit) Watch the 2 hour Ania video HERE, build the app yourself, and show us the completed app.
  3. Submit your homework here

That's it, you are done! Expect an email next week!

🏁 Start Hands-on

LAB 1 - Getting Started with Database

1.1 - Getting Started with Database

ASTRA is the simplest way to run both Cassandra and Pulsar with zero operations at all - just push the button and get your clusters. No credit card required

βœ….1.1.a- Create Astra Account

↗️ Right Click and select open as a new Tab...

image

βœ….1.1.b- Create Astra Database

image

# Field Name Field Value
1 Database Name workshops
2 Keyspace Name tiktok_keyspace
3 Cloud Provider Google Cloud Plaform
4 Area North America
5 Region Moncks Corner, South Carolina

πŸ–₯️ Output

image

πŸ–₯️ Output

image

βœ….1.1.c- Database was already existing

Here are some special situations you might encounter.

ℹ️ Hibernated Database:

If the DB workshops already exists but is hibernated (you have not use it for a while):

  • Click the [Resume Database] button on the top right-hand corner.

image

ℹ️ Database already exists, create keyspace tiktok_keyspace

If DB exists and is active but tiktok_keyspace keyspace is not present you need to create the keyspace.

  • Click button [Add Keyspace] on the database dashboard (bottom right-hand corner)
  • Provide the keyspace name tiktok_keyspace
  • Click button [Save]. The database will switch in maintenance mode for a few seconds, you are set.

image

LAB 2 - Document API

2.1 Using Document API

βœ….2.1.a- Open Swagger User Interface

image

πŸ–₯️ Swagger UI

image

βœ….2.1.b- Lists Collections

image

image

Field Value
X-Cassandra-Token autopopulated
namespace-id tiktok_keyspace

The output is empty (expected):

[]

βœ….2.1.c- Create Collection story

Field Value
X-Cassandra-Token autopopulated
namespace-id tiktok_keyspace
body {"name":"story"}

image

πŸ–₯️ Output

{
 "data": [
   {
     "name": "story",
     "upgradeAvailable": false
   }
 ]
}

βœ….2.1.d- Create a first document

With a document oriented API there is no strict schema to comply with. As such let us decide what a story could look like.

Field Value
X-Cassandra-Token autopopulated
namespace-id tiktok_keyspace
collection-id story

body:

{
  "name": "Mo Farooq",
  "username": "mofarooq32",
  "avatar": "https://i.imgur.com/9KYq7VG.png",
  "is_followed": true,
  "video": "https://i.imgur.com/FTBP02Y.mp4",
  "caption": "These ducks are MEGA cute",
  "likes": 10,
  "comments": 2,
  "button_visible": true
}

πŸ–₯️ Output

{
 "documentId": "8aa07632-4ffb-46e5-9d78-b32e21847221"
}

βœ….2.1.e- Search documents in a collections

Field Value
X-Cassandra-Token autopopulated
namespace-id tiktok_keyspace
collection-id story
where {"username": {"$eq": "mofarooq32"}}

πŸ–₯️ Output

{
 "data": {
   "8aa07632-4ffb-46e5-9d78-b32e21847221": {
     "avatar": "https://i.imgur.com/9KYq7VG.png",
     "button_visible": true,
     "caption": "These ducks are MEGA cute",
     "comments": 2,
     "is_followed": true,
     "likes": 10,
     "name": "Mo Farooq",
     "username": "mofarooq32",
     "video": "https://i.imgur.com/FTBP02Y.mp4"
   }
 }
}

βœ….2.1.f- Update a document

Field Value
X-Cassandra-Token autopopulated
namespace-id tiktok_keyspace
collection-id story
document-id document you got before here 8aa07632-4ffb-46e5-9d78-b32e21847221

body:

{
  "name": "New Name",
  "username": "mofarooq32",
  "avatar": "https://i.imgur.com/9KYq7VG.png",
  "is_followed": true,
  "video": "https://i.imgur.com/FTBP02Y.mp4",
  "caption": "These ducks are MEGA cute",
  "likes": 10,
  "comments": 2,
  "button_visible": true
}

βœ….2.1.g- Delete a document

Field Value
X-Cassandra-Token autopopulated
namespace-id tiktok_keyspace
collection-id story
document-id document you got before here 8aa07632-4ffb-46e5-9d78-b32e21847221

πŸ–₯️ Output

Code 204
access-control-allow-credentials: true 
access-control-allow-origin: https://50b31120-2303-4f45-a9dd-1cfb03e24ff1-us-east1.apps.astra.datastax.com 
access-control-expose-headers: Date 
date: Mon,12 Dec 2022 18:12:43 GMT 
vary: Origin 

2.2 - Create Astra Credentials

When using swagger in the user interface, you are already authenticated against the API. When using a third party application you will need a token.

βœ….2.2.a- Create Astra Credentials

ℹ️ Skip this step is you already have a token. You can reuse the same token in our other workshops, too.

image

βœ….2.2.b- Download Astra Credentials

image

⚠️ Important

The instructor will show you on screen how to create a token 
but will have to destroy to token immediately for security reasons.

Notice the clipboard icon at the end of each value.

LAB 3 - IDE Setup

3.1 - Netlify Site Setup

↗️ Right Click and select open as a new Tab...

Deploy to Netlify

image

3.2 - Launch GitPod

βœ….3.2.a- Open YOUR GITHUB REPOSITORY README

WAIT! Before moving on ensure you are working out of YOUR repository, not the datastaxdevs repository.

correct notcorrect

If you are still using the datastaxdevs repo please ensure to follow the previous step, step3 to get to your repo.

βœ….3.2.b- Open Gitpod IDE

Last time, be certain to click this when you MOVED TO YOUR REPOSITORY (not datastaxdevs)

↗️ Right Click and select open as a new Tab...

Open in Gitpod

βœ….3.2.c- Validating your not using datastaxdevs

git remote -v

πŸ–₯️ Output

origin  https://github.com/clun/workshop-astra-tik-tok.git (fetch)
origin  https://github.com/clun/workshop-astra-tik-tok.git (push)
If the result returned from the command displays **`datastaxdevs`** then you are not in the correct repository. If this is the case please [repeat step 3 above](#3-access-your-github-repository), otherwise just move on to the next step.

3.3 - Astra CLI Setup

βœ….3.3.a- Save your token

Locate an open terminal and enter the following command replacing <YOUR_TOKEN> by the one we created before starting with AstraCS:.. it should be in the CSV we download before

astra setup -t <YOUR_TOKEN>

βœ….3.3.b- Validate your configuration

astra user list

πŸ–₯️ Output

gitpod /workspace/workshop-astra-tik-tok (master) $ astra user list
+--------------------------------------+-----------------------------+---------------------+
| User Id                              | User Email                  | Status              |
+--------------------------------------+-----------------------------+---------------------+
| b665658a-ae6a-4f30-a740-2342a7fb469c | cedrick.lunven@datastax.com | active              |
+--------------------------------------+-----------------------------+---------------------+

βœ….3.3.c- List Database to see workshops

astra db list

πŸ–₯️ Output

+---------------------+--------------------------------------+---------------------+----------------+
| Name                | id                                   | Default Region      | Status         |
+---------------------+--------------------------------------+---------------------+----------------+
| mtg                 | dde308f5-a8b0-474d-afd6-81e5689e3e25 | eu-central-1        | ACTIVE         |
| workshops           | 50b31120-2303-4f45-a9dd-1cfb03e24ff1 | us-east1            | ACTIVE         |
+---------------------+--------------------------------------+---------------------+----------------+

βœ….3.3.d- Get db details

astra db get workshops

πŸ–₯️ Output

gitpod /workspace/workshop-astra-tik-tok (master) $ astra db get workshops
+------------------------+-----------------------------------------+
| Attribute              | Value                                   |
+------------------------+-----------------------------------------+
| Name                   | workshops                               |
| id                     | 50b31120-2303-4f45-a9dd-1cfb03e24ff1    |
| Status                 | ACTIVE                                  |
| Default Cloud Provider | GCP                                     |
| Default Region         | us-east1                                |
| Default Keyspace       | tiktok_keyspace                         |
| Creation Time          | 2022-12-12T11:14:58Z                    |
|                        |                                         |
| Keyspaces              | [0] tiktok_keyspace                     |
|                        |                                         |
|                        |                                         |
| Regions                | [0] us-east1                            |
|                        |                                         |
+------------------------+-----------------------------------------+

βœ….3.3.e- Create configuration file

astra db create-dotenv workshops -k tiktok_keyspace -r us-east1
cat .env

πŸ–₯️ Output

ASTRA_DB_APPLICATION_TOKEN="AstraCS:gfYSGwpaFNGmUZnZTvaCp......"
ASTRA_DB_GRAPHQL_URL="https://.....-us-east1.apps.astra.datastax.com/api/graphql/tiktok_keyspace"
ASTRA_DB_GRAPHQL_URL_ADMIN="https://.....-us-east1.apps.astra.datastax.com/api/graphql-admin"
ASTRA_DB_GRAPHQL_URL_PLAYGROUND="https://.....-us-east1.apps.astra.datastax.com/api/playground"
ASTRA_DB_GRAPHQL_URL_SCHEMA="https://.....-us-east1.apps.astra.datastax.com/api/graphql-schema"
ASTRA_DB_ID="....."
ASTRA_DB_KEYSPACE="tiktok_keyspace"
ASTRA_DB_REGION="us-east1"
ASTRA_DB_REST_URL="https://.....-us-east1.apps.astra.datastax.com/api/rest"
ASTRA_DB_REST_URL_SWAGGER="https://.....-us-east1.apps.astra.datastax.com/api/rest/swagger-ui/"
ASTRA_DB_SECURE_BUNDLE_PATH="/home/gitpod/.astra/scb/scb_....._us-east1.zip"
ASTRA_DB_SECURE_BUNDLE_URL="secured_url"
ASTRA_ORG_ID="f9460f14-9879-4ebe-83f2-48d3f3dce13c"
ASTRA_ORG_NAME="cedrick.lunven@datastax.com"
ASTRA_ORG_TOKEN="AstraCS:gfYSGwpaFNGmUZnZT....."

3.4 - Netlify CLI Setup

βœ….3.4.a- Install the package

In the workshop-astra-tik-tok directory run the following command to install the netlify-cli

npm install -g netlify-cli

πŸ–₯️ Output

3.5 Launch your app

βœ….3.5.a- Start application

netlify dev

The application should automatically launch in the GitPod preview pane. You might see an error in the log for this firt launch, some data is inserted to the database.

πŸ–₯️ Output

β—ˆ Netlify Dev β—ˆ
β—ˆ Ignored general context env var: LANG (defined in process)
β—ˆ Injected .env file env var: ASTRA_DB_APPLICATION_TOKEN
β—ˆ Injected .env file env var: ASTRA_DB_GRAPHQL_URL
β—ˆ Injected .env file env var: ASTRA_DB_GRAPHQL_URL_ADMIN
β—ˆ Injected .env file env var: ASTRA_DB_GRAPHQL_URL_PLAYGROUND
β—ˆ Injected .env file env var: ASTRA_DB_GRAPHQL_URL_SCHEMA
β—ˆ Injected .env file env var: ASTRA_DB_ID
β—ˆ Injected .env file env var: ASTRA_DB_KEYSPACE
β—ˆ Injected .env file env var: ASTRA_DB_REGION
β—ˆ Injected .env file env var: ASTRA_DB_REST_URL
β—ˆ Injected .env file env var: ASTRA_DB_REST_URL_SWAGGER
β—ˆ Injected .env file env var: ASTRA_DB_SECURE_BUNDLE_PATH
β—ˆ Injected .env file env var: ASTRA_DB_SECURE_BUNDLE_URL
β—ˆ Injected .env file env var: ASTRA_ORG_ID
β—ˆ Injected .env file env var: ASTRA_ORG_NAME
β—ˆ Injected .env file env var: ASTRA_ORG_TOKEN
β—ˆ Loaded function add http://localhost:8888/.netlify/functions/add.
β—ˆ Loaded function addData http://localhost:8888/.netlify/functions/addData.
β—ˆ Loaded function edit http://localhost:8888/.netlify/functions/edit.
β—ˆ Loaded function posts http://localhost:8888/.netlify/functions/posts.
β—ˆ Functions server is listening on 36661
β—ˆ Setting up local development server

────────────────────────────────────────────────────────────────
  Netlify Build                                                 
────────────────────────────────────────────────────────────────

❯ Version
  @netlify/build 28.4.5

❯ Flags
  {}

❯ Current directory
  /workspace/workshop-astra-tik-tok

❯ Config file
  /workspace/workshop-astra-tik-tok/netlify.toml

❯ Context
  dev

────────────────────────────────────────────────────────────────
  1. Run command for local development                          
────────────────────────────────────────────────────────────────

β—ˆ Starting Netlify Dev with Create React App

> tik-tok-stargate@0.1.0 start
> react-scripts start

β„Ή ο½’wdsο½£: Project is running at http://10.0.5.2/
β„Ή ο½’wdsο½£: webpack output is served from 
β„Ή ο½’wdsο½£: Content not from webpack is served from /workspace/workshop-astra-tik-tok/public
β„Ή ο½’wdsο½£: 404s will fallback to /
Starting the development server...

Compiled successfully!

You can now view tik-tok-stargate in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://10.0.5.2:3000

Note that the development build is not optimized.
To create a production build, use npm run build.

βœ” Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml

(dev.command completed in 9.4s)

   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚                                                 β”‚
   β”‚   β—ˆ Server now ready on http://localhost:8888   β”‚
   β”‚                                                 β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β ¦ Setting up the Edge Functions environment. This may take a couple of minutes.Request from ::ffff:192.168.9.75: POST /.netlify/functions/addData
β § Setting up the Edge Functions environment. This may take a couple of minutes.Request from ::ffff:192.168.9.75: GET /.netlify/functions/posts
β ™ Setting up the Edge Functions environment. This may take a couple of minutes.Response with status 200 in 341 ms.
β ¦ Setting up the Edge Functions environment. This may take a couple of minutes.Response with status 200 in 1609 ms.
βœ” Setting up the Edge Functions environment. This may take a couple of minutes.

start

LAB 4 - Coding Against DB

4.1 - Document API

Using same instruction as #2.1 execute the following operation with the Document Api using swagger UI.

βœ….4.1.a- Reopen Swagger

Now that we have locally deployed our TikTok app, let's take a look at this in our database. Head to your Astra DB dashboard and click the Connect button next to your database ('workshops').

db_connect

Then scroll down to the section called 'Launching SwaggerUI' and click the link. We'll be using SwaggerUI to make api calls to our database and see the results.

swaggerui_link

βœ….4.1.a- List Collections

Open up the first section labelled "List collections in namespace" and click the button "Try it out".

swaggerui_link

πŸ–₯️ Output

{
  "data": [
    {
      "name": "story",
      "upgradeAvailable": false
    },
    {
      "name": "tktkposts",
      "upgradeAvailable": false
    }
  ]
}

βœ….4.1.b- List Documents of tktkposts

swaggerui_link

Field Value
X-Cassandra-Token autopopulated
namespace-id tiktok_keyspace
collection-id tktkposts

Let the rest of the fields untouched. You can see that every query is paged and default page size is 3.And we see all of the documents stored in our database.

swaggerui_link

πŸ–₯️ Output

{
  "pageState": "ATIA8H_____wf____w==",
  "data": {
    "0": {
      "avatar": "https://i.imgur.com/jONHmE5.png",
      "button_visible": true,
      "caption": "Art is for everyone",
      "comments": 20,
      "id": 0,
      "is_followed": true,
      "likes": 231,
      "name": "Lana Del Mont",
      "timestamp": "2020-09-10T09:08:31.020Z",
      "username": "lana_del_away",
      "video": "https://i.imgur.com/H9UX0Jm.mp4"
    },
    "2": {
      "avatar": "https://i.imgur.com/eX3hkoc.png",
      "button_visible": true,
      "caption": "Happiest of Birthdays my Angel",
      "comments": 4,
      "id": 2,
      "is_followed": true,
      "likes": 2,
      "name": "Angela Lee",
      "timestamp": "2020-04-10T09:08:31.020Z",
      "username": "angiecakes",
      "video": "https://i.imgur.com/al6MLay.mp4"
    },
    "3": {
      "avatar": "https://i.imgur.com/IigY4Hm.png",
      "button_visible": true,
      "caption": "The new normal",
      "comments": 2,
      "id": 3,
      "is_followed": false,
      "likes": 10,
      "name": "Nina Xen",
      "timestamp": "2020-05-10T09:08:31.020Z",
      "username": "nina_lina",
      "video": "https://i.imgur.com/Kzvbeup.mp4"
    }
  }
}

4.2 - AstraJS Client

βœ….4.2.1 - Initialization

We are using the @astrajs/collections library to make the connection using the Document API. To do so, we start by creating a client.

(See: functions/utils/astraClient.js)

const { createClient } = require("@astrajs/collections");

let astraClient = null;

const getAstraClient = async () => {
  if (astraClient === null) {
    astraClient = await createClient(
      {
        astraDatabaseId: process.env.ASTRA_DB_ID,
        astraDatabaseRegion: process.env.ASTRA_DB_REGION,
        applicationToken: process.env.ASTRA_DB_APPLICATION_TOKEN,
      },
      30000
    );
  }
  return astraClient;
};

Here we are defining a new method called getAstraClient that uses the createClient method from our astrajs library to create a connection to our database. We then provide it the needed database credentials we added to our environment variables earlier;

Then we return the astraClient we can then use in our API calls.

We also need to create a document collection to store our data.

const getCollection = async () => {
  const documentClient = await getAstraClient();
  return documentClient
    .namespace(process.env.ASTRA_DB_KEYSPACE)
    .collection("tktkposts");
};

In this method, we are using our previously created getAstraClient method to initialize the database connection, and then create a collection in the keyspace we defined in our environment variables;

We will call the collection tktkposts.

βœ….4.2.b - Create document with @astrajs/collections

For our TikTok app, we will not be dealing with the Document API directly. Instead @astrajs/collections does that for us, and provides us with easy to use methods.

If you want a comprehensive list of the capabilities of @astrajs/collections, check out this documentation: AstraJS Collections

The create method is used when we want to add documents to our collection. For example, in functions/add.js we get our collection from the database using our getCollection method.

const users = await getCollection();

Then we use the create method to create a document, providing the id and body of the document.

try {
    const user = await users.create(id, event.body);
    return {
      statusCode: 200,
      body: JSON.stringify(user),
    };
}

βœ….4.2.c - Update document with @astrajs/collections

The update method is used to update portions of existing documents. Take a look at functions/edit.js. Again we use getCollection() to get our collection from the database, then we use the update method, provide it with an id for the document we want to edit, and the data that needs updating.

try {
    users.update(body.userId, body.data);
    return {
      statusCode: 200,
    };
  }

βœ….4.2.d - Search document with @astrajs/collections

And finally the find method is used to retrieve documents. In functions/posts.js we are again using getCollections() and using the find method on the result.

try {
    const res = await users.find({});
    return {
      statusCode: 200,
      body: JSON.stringify(Object.keys(res).map((i) => res[i])),
    };
  }

In this case, we are passing an empty object to retrieve all documents. In a real-world scenario, we would pass a qualifier to get only the documents relevant to a specific user.

4.3 - Serverless configuration

Take a look at netlify.toml.

[build]
command = "npm run build"
functions = "functions"
publish = "build"

This is the configuration file we include in our codebase that tells Netlify how to build our app. In our case it's really simple. First we give the build command to build our app: npm run build. Then we tell Netlify where to find our serverless functions, and finally where to find the resulting app after build.

So Netlify will create endpoints for our serverless functions based on the files it finds in our functions folder.

For example, we have a function called posts.js. As we saw before, this function returns all of the current posts in our database. Netlify will see that file in our functions directory and dynamically create an endpoint at /.netlify/functions/posts

// Declaring 'getCollection'
const { getCollection } = require("./utils/astraClient");

// Function exported as a REST API
exports.handler = async function () {
  // Accessing the collection tkt
  const tktkpostsCollection = await getCollection();
  try {
    // Access POST
    const res = await tktkpostsCollection.find({});
    return {
      // Return POSTS in the body
      statusCode: 200,
      body: JSON.stringify(Object.keys(res).map((i) => res[i])),

[...]

βœ… We can see these functions in our Netlify account.

netlify_functions

From here we can see all our functions and get direct links as well as watch real time logs.

We can also see this in action by manually going to the endpoint on our Netlify site: [your-site-url]/.netlify/functions/posts.

netlify_endpoint

4.4 - React Component

The front end leverages on React. The code is organized in pages and each pages import a list of components.

βœ….4.4.a - React Router

There are 2 pages updload and Home and describe in index.js

<Switch>
  <Route path= "/upload" component={Upload}/>
  <Route path= "/" component={Home}/>
</Switch>

netlify_endpoint

βœ….4.4.b - Upload Page

Access through the cloud icon of directly on /upload it is a static HTML form to create new posts.

netlify_endpoint

As you can see Upload.js there are no component used.

<form onSubmit={handleSubmit}>
    <div className='section'>
<!-- rest is omitted --> 
 const handleSubmit = async (e) => {
 e.preventDefault()
 // Create payload
 const data =  {
        id: id,
        name: name,
        username: username,
        avatar: avatar,
        is_followed: false,
        video: video,
        caption: caption,
        likes: 0,
        comments: 0,
        timestamp: timestamp,
        button_visible: false  
  }
  // Post Payload to Netlify functions
  axios.post('/.netlify/functions/add', data)
       .then((response) => { console.log(response)})
       .catch((err) => { console.error(err)})

βœ….4.4.b - Home Page

The page load data coming from the collection in Astra and push the information to multiple components that renders sections of the page.

netlify_endpoint

More on Home.js.

LAB 5 - Netlify Deployments

5.1 - Connect Netlify to your site

Execute each of the commands below to link your code to your Netlify deployment.

βœ….5.1.a - Authenticate in Netlify

netlify login

Note, when using GitPod the preview pane will not display this properly. You must click the "open in a new window" button in the very top right of the preview pane.

swaggerui_link

πŸ–₯️ Output

Logging into your Netlify account...
Opening https://app.netlify.com/authorize?response_type=ticket&ticket=774701161c326912e718b3a86096f375
You are now logged into your Netlify account!
Run netlify status for account details
To see all available commands run: netlify help
netlify link
> Use current git remote origin (https://github ...`

swaggerui_link

πŸ–₯️ Output

netlify link will connect this folder to a site on Netlify
? How do you want to link this folder to a site? Use current git remote origin (https://github.com/clun/workshop-astra-tik-tok)
Looking for sites connected to 'https://github.com/clun/workshop-astra-tik-tok'...
Directory Linked
Admin url: https://app.netlify.com/sites/fanciful-licorice-ea1437
Site url:  https://fanciful-licorice-ea1437.netlify.app
You can now run other `netlify` cli commands in this directory

βœ….5.1.b - Import configuration in site

netlify env:import .env

5.2 - Deploy to production

Now that you've hooked everything up, time to deploy to production.

netlify build

πŸ–₯️ Output

────────────────────────────────────────────────────────────────
  Netlify Build                                                 
────────────────────────────────────────────────────────────────

❯ Version
  @netlify/build 28.4.5

❯ Flags
  dry: false
  offline: false

❯ Current directory
  /workspace/workshop-astra-tik-tok

❯ Config file
  /workspace/workshop-astra-tik-tok/netlify.toml

❯ Context
  production

────────────────────────────────────────────────────────────────
  1. build.command from netlify.toml                            
────────────────────────────────────────────────────────────────

$ npm run build

tik-tok-stargate@0.1.0 build
react-scripts build

Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  616.87 KB  build/static/js/2.82b8325c.chunk.js
  2.32 KB    build/static/js/main.fd7c93f3.chunk.js
  966 B      build/static/css/main.9d8c5499.chunk.css
  780 B      build/static/js/runtime-main.f09b770f.js

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

 npm install -g serve
 serve -s build

Find out more about deployment here:

  https://cra.link/deployment

(build.command completed in 35.1s)

────────────────────────────────────────────────────────────────
  2. Functions bundling                                         
────────────────────────────────────────────────────────────────

Packaging Functions from functions directory:
 - add.js
 - addData.js
 - edit.js
 - posts.js

(Functions bundling completed in 6.1s)

────────────────────────────────────────────────────────────────
  Netlify Build Complete                                        
────────────────────────────────────────────────────────────────

(Netlify Build completed in 41.3s)
netlify deploy --prod

πŸ–₯️ Output

Deploy path:        /workspace/workshop-astra-tik-tok/build
Functions path:     /workspace/workshop-astra-tik-tok/functions
Configuration path: /workspace/workshop-astra-tik-tok/netlify.toml
Deploying to main site URL...
βœ” Deploying functions from cache (use --skip-functions-cache to override)
βœ” Finished hashing 17 files and 4 functions
βœ” CDN requesting 0 files and 4 functions
βœ” Finished uploading 4 assets
βœ” Deploy is live!

Logs:              https://app.netlify.com/sites/fanciful-licorice-ea1437/deploys/63974804721fc334dc247455
Unique Deploy URL: https://63974804721fc334dc247455--fanciful-licorice-ea1437.netlify.app
Website URL:       https://fanciful-licorice-ea1437.netlify.app
gitpod /workspace/workshop-astra-tik-tok (master) $ 
netlify open:site

πŸ–₯️ Output

Opening "fanciful-licorice-ea1437" site url:
https://fanciful-licorice-ea1437.netlify.app

Extra Resources

Video tutorial with Ania Kubow

Thank you to our wonderful friend Ania Kubow for producing the TikTok clone. If you are not aware of Ania and love learning about coding you should absolutely check out her YouTube channel listed below.

While we focused on getting you up and running to production with Astra DB and Netlify, Ania's video will dig into more details on the app itself. Check it out to dig in more.

Running Astra DB Tik-Tok

We're using Create-React-App and the Astra DB Document API to create a simple Tik-Tok clone. Follow along in this video tutorial: https://youtu.be/IATOicvih5A.

Follow the instructions below to get started.

If you did like this video, please hit the Like and Subscribe button so I know to make more!