Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EDU-1816] - Add NPM Workspaces to examples #2419

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_PUBLIC_ABLY_KEY=
NEXT_PUBLIC_ABLY_KEY=
10 changes: 5 additions & 5 deletions examples/auth-generate-jwt/javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ git clone [email protected]:ably/docs.git
2. Change directory:

```sh
cd /examples/auth-generate-jwt/javascript/
cd /examples/
```

3. Install dependencies:
Expand All @@ -25,13 +25,13 @@ yarn install
4. Run the frontend client:

```sh
yarn run dev
yarn run auth-generate-jwt-javascript
```

5. In a new tab, change directory:

```sh
cd /examples/auth-generate-jwt/server/
cd /examples/
Comment on lines 31 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're already in this directory with the workspace changes. I think the auth ones will need rewording as you just need to update the .env files rather than messing around changing directories now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but if you run yarn run auth-generate-jwt-javascript you're then opening a second terminal to run the server command, which means you'll likely have to navigate to that directory again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 🤦

```

6. Rename the environment file:
Expand All @@ -40,7 +40,7 @@ cd /examples/auth-generate-jwt/server/
mv .env.example .env.local
```

7. In `.env.local` update the value of `ABLY_API_KEY` to be your Ably API key.
7. In `.env.local` update the value of `VITE_PUBLIC_ABLY_KEY` to be your Ably API key.

8. Install dependencies:

Expand All @@ -51,7 +51,7 @@ yarn install
9. Run the backend server:

```sh
yarn run dev
yarn run auth-generate-jwt-server
```

10. Try it out by opening a tab to [http://localhost:5173/](http://localhost:5173/) with your browser to see the result.
14 changes: 1 addition & 13 deletions examples/auth-generate-jwt/javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
{
"name": "auth-request-token",
"name": "auth-generate-jwt-javascript",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"devDependencies": {
"autoprefixer": "^10.4.20",
"dotenv": "^16.4.5",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.13",
"typescript": "^5.6.3"
},
"dependencies": {
"ably": "^2.3.1",
"nanoid": "^5.0.7",
"vite": "^5.4.12"
}
}
20 changes: 10 additions & 10 deletions examples/auth-generate-jwt/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ git clone [email protected]:ably/docs.git
2. Change directory:

```sh
cd /examples/auth-generate-jwt/react/
cd /examples/
```

3. Install dependencies:
Expand All @@ -55,13 +55,13 @@ yarn install
4. Run the frontend client:

```sh
yarn run dev
yarn run auth-generate-jwt-react
```

5. In a new tab, change directory:

```sh
cd /examples/auth-generate-jwt/server/
cd /examples/
```

6. Rename the environment file:
Expand All @@ -70,7 +70,7 @@ cd /examples/auth-generate-jwt/server/
mv .env.example .env.local
```

7. In `.env.local` update the value of `NEXT_PUBLIC_ABLY_KEY` to be your Ably API key.
7. In `.env.local` update the value of `VITE_PUBLIC_ABLY_KEY` to be your Ably API key.

8. Install dependencies:

Expand All @@ -81,7 +81,7 @@ yarn install
9. Run the backend server:

```sh
yarn run dev
yarn run auth-generate-jwt-server
```

10. Try it out by opening a tab to [http://localhost:3000/](http://localhost:3000/) with your browser to see the result.
Expand All @@ -97,7 +97,7 @@ git clone [email protected]:ably/docs.git
2. Change directory:

```sh
cd /examples/auth-generate-jwt/javascript/
cd /examples/
```

3. Install dependencies:
Expand All @@ -109,13 +109,13 @@ yarn install
4. Run the frontend client:

```sh
yarn run dev
yarn run auth-generate-jwt-javascript
```

5. In a new tab, change directory:

```sh
cd /examples/auth-generate-jwt/server/
cd /examples/
```

6. Rename the environment file:
Expand All @@ -135,7 +135,7 @@ yarn install
9. Run the backend server:

```sh
yarn run dev
yarn run auth-generate-jwt-server
```

10. Try it out by opening a tab to [http://localhost:5173/](http://localhost:5173/) with your browser to see the result.
Expand All @@ -144,7 +144,7 @@ yarn run dev

// React

In CodeSandbox, rename the `.env.example` file to `.env.local` and update the value of your `NEXT_PUBLIC_ABLY_KEY` variable to use your Ably API key.
In CodeSandbox, rename the `.env.example` file to `.env.local` and update the value of your `VITE_PUBLIC_ABLY_KEY` variable to use your Ably API key.

// Javascript

Expand Down
10 changes: 5 additions & 5 deletions examples/auth-generate-jwt/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ git clone [email protected]:ably/docs.git
2. Change directory:

```sh
cd /examples/auth-generate-jwt/react/
cd /examples/
```

3. Install dependencies:
Expand All @@ -25,13 +25,13 @@ yarn install
4. Run the frontend client:

```sh
yarn run dev
yarn run auth-generate-jwt-react
```

5. In a new tab, change directory:

```sh
cd /examples/auth-generate-jwt/server/
cd /examples/
```

6. Rename the environment file:
Expand All @@ -40,7 +40,7 @@ cd /examples/auth-generate-jwt/server/
mv .env.example .env.local
```

7. In `.env.local` update the value of `ABLY_API_KEY` to be your Ably API key.
7. In `.env.local` update the value of `VITE_PUBLIC_ABLY_KEY` to be your Ably API key.

8. Install dependencies:

Expand All @@ -51,7 +51,7 @@ yarn install
9. Run the backend server:

```sh
yarn run dev
yarn run auth-generate-jwt-server
```

10. Try it out by opening a tab to [http://localhost:3000/](http://localhost:3000/) with your browser to see the result.
19 changes: 1 addition & 18 deletions examples/auth-generate-jwt/react/package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
{
"name": "react",
"name": "auth-generate-jwt-react",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"ably": "^2.4.0",
"nanoid": "^5.0.9",
"next": "14.2.21",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "15.0.3",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}
1 change: 0 additions & 1 deletion examples/auth-generate-jwt/server/.env.example

This file was deleted.

15 changes: 1 addition & 14 deletions examples/auth-generate-jwt/server/package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
{
"name": "server",
"name": "auth-generate-jwt-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "ts-node src/server.ts",
"build": "tsc",
"start": "node dist/server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/express": "^5.0.0",
"@types/node": "^22.10.1",
"ably": "^2.5.0",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.1",
"ts-node": "^10.9.2",
"typescript": "^5.7.2"
}
}
7 changes: 4 additions & 3 deletions examples/auth-generate-jwt/server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import express from 'express';
import path from 'path';
import dotenv from 'dotenv';
import cors from 'cors';
import crypto from 'crypto';

dotenv.config({ path: '.env.local' });
dotenv.config({ path: path.resolve(__dirname, '../../../.env.local') });

const app = express();
const port = 3001;
Expand All @@ -22,11 +23,11 @@ function base64urlEncode(str: string) {
app.get('/generate-jwt', async (_req, res) => {
console.log('1 - /generate-jwt endpoint called');

const ablyApiKey = process.env.ABLY_API_KEY || '';
const ablyApiKey = process.env.VITE_PUBLIC_ABLY_KEY || '';
const [apiKeyName, apiKeySecret] = ablyApiKey.split(':');
try {
if (ablyApiKey === '') {
throw new Error('ABLY_API_KEY is not set');
throw new Error('VITE_PUBLIC_ABLY_KEY is not set');
}

const header = {
Expand Down
7 changes: 0 additions & 7 deletions examples/auth-generate-jwt/server/vite.config.ts

This file was deleted.

Loading