Skip to content

Commit b6253e8

Browse files
Merge pull request #6 from ably-labs/nextjs-chat-app-netlify
netlify changes
2 parents 7e4ec82 + c7331ea commit b6253e8

31 files changed

+23629
-2360
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ABLY_API_KEY=

.eslintrc.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
{
2-
"extends": "next/core-web-vitals"
2+
"extends": [
3+
"next/core-web-vitals",
4+
"prettier",
5+
"plugin:react/recommended"
6+
],
7+
"plugins": [
8+
"react"
9+
],
10+
"rules": {
11+
"react/react-in-jsx-scope": "off",
12+
"react/prop-types": "off"
13+
},
14+
"settings": {
15+
"react": {
16+
"version": "detect"
17+
}
18+
},
19+
"parserOptions": {
20+
"ecmaFeatures": {
21+
"jsx": true
22+
},
23+
"ecmaVersion": 2021,
24+
"sourceType": "module"
25+
}
326
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ yarn-error.log*
2929
.env.development.local
3030
.env.test.local
3131
.env.production.local
32+
33+
# local Netlify folder
34+
.netlify

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 20.10.0

README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Building a Realtime Chat App with Next.js, Ably, and Vercel
1+
# Building a Realtime Chat App with Next.js, Ably, and Netlify
22

33
Live example at: <https://next-js-chat-app.vercel.app>
44

@@ -18,20 +18,22 @@ It demonstrates the use of:
1818

1919
The project uses the following components:
2020

21-
- [Next.js](https://nextjs.org/) is a React framework from [Vercel](https://vercel.com/). It is used to build static web applications with server side rendering, serverless functions and seamless hosting. It's a framework that takes the React knowledge you already have, and puts some structure and conventions in place.
21+
- [Next.js](https://nextjs.org/) is a React framework used to build static web applications with server side rendering, serverless functions and seamless hosting. It's a framework that takes the React knowledge you already have, and puts some structure and conventions in place.
2222

2323
- [Ably](https://ably.com/) is realtime, pub/sub messaging platform with a suite of integrated services to deliver complete realtime functionality directly to end-users.
2424

25-
- [Vercel](https://vercel.com/) is a hosting platform, built from the ground up to host Next.js apps, and Serverless Functions with them.
25+
- [Netlify](https://netlify.com/) is a hosting platform that provides continuous deployment, serverless functions, and a global CDN for modern web projects.
2626

2727
- [React](https://reactjs.org/) is a JavaScript library for building user interfaces with encapsulated components that manage their own state.
2828

29+
- [TypeScript](https://www.typescriptlang.org/) is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.
30+
2931
## What are we going to build?
3032

31-
![The UI of the chat app we'll build. It is a window with speech bubbles for text.](https://cdn.glitch.com/0cb30add-c9ef-4c00-983c-e12deb0d4080%2Fchatapp.png?v=1612279601157)
32-
*The UI of the app we'll build with this walkthrough*
33+
![The UI of the chat app we'll build. It is a window with speech bubbles for text.](https://cdn.glitch.com/0cb30add-c9ef-4c00-983c-e12deb0d4080%2Fchatapp.png?v=1612279601157)
34+
*The UI of the app we'll build with this walkthrough*
3335

34-
We'll build a realtime chat app that runs in the browser. It will be built upon the Next.js [create-next-app](https://nextjs.org/docs/api-reference/create-next-app) template, it will contain a React component which will use Ably to send and receive messages. We'll also write a Next.js serverless function which will be used to connect to Ably.
36+
We'll build a realtime chat app that runs in the browser. It will be built upon the Next.js [create-next-app](https://nextjs.org/docs/api-reference/create-next-app) template, it will contain a React component which will use Ably to send and receive messages. We'll also write a serverless function which will be used to authenticate the client with Ably.
3537

3638
## Building & running locally
3739

@@ -40,8 +42,8 @@ We'll build a realtime chat app that runs in the browser. It will be built upon
4042
In order to build and deploy this app, you will need:
4143

4244
- **An Ably account** for sending messages: [Create an account with Ably for free](https://ably.com/signup).
43-
- **A Vercel Account** for hosting on production: [Create an account with Vercel for free](https://vercel.com/signup).
44-
- **Node 16** or greater: [Install Node](https://nodejs.org/en/).
45+
- **A Netlify Account** for hosting on production: [Create an account with Netlify for free](https://netlify.com/signup).
46+
- **Node 20** or greater: [Install Node](https://nodejs.org/en/).
4547

4648
You'll also need an API key from Ably to authenticate with the Ably Service. To get an API key, once you have [created an Ably account](https://ably.com/signup):
4749

@@ -58,24 +60,35 @@ ABLY_API_KEY=your-ably-api-key:goes-here
5860
```
5961

6062
2. Run `npm install`.
61-
3. Run `npm run dev`.
63+
3. Run `npm run netlify:dev` to start the Netlify development server.
64+
65+
The Netlify development server will spin up and you'll see a demo chat application.
66+
67+
> Note: You can also use `npm run dev` to run just the Next.js development server without Netlify functions, but for the full experience with serverless functions, use `npm run netlify:dev`.
68+
69+
### TypeScript Support
70+
71+
This project uses TypeScript for type safety. Here are some useful commands for TypeScript development:
72+
73+
- `npm run type-check`: Run TypeScript's type checker without emitting files
74+
- `npm run dev`: The Next.js development server automatically type-checks your code as you develop
6275

63-
The Next.js dev server will spin up and you'll see a demo chat application.
76+
When creating new components or functions, use the `.tsx` extension for React components and `.ts` for plain TypeScript files. The project is configured with a `tsconfig.json` file that provides sensible defaults for Next.js TypeScript projects.
6477

65-
## Hosting on Vercel
78+
## Hosting on Netlify
6679

67-
We're using `Vercel` as our development server and build pipeline.
80+
We're using `Netlify` as our development server and build pipeline.
6881

69-
> The easiest way to deploy Next.js to production is to use the Vercel platform from the creators of Next.js. Vercel is an all-in-one platform with Global CDN supporting static & Jamstack deployment and Serverless Functions.
70-
<cite>-- [The Next.js documentation](https://nextjs.org/docs/deployment)</cive>
82+
> Netlify is a powerful platform for building, deploying, and managing modern web projects. It provides continuous deployment, serverless functions, and a global CDN.
83+
<cite>-- [The Netlify documentation](https://docs.netlify.com/)</cite>
7184
72-
In order to deploy your new chat app to Vercel you'll need to:
85+
In order to deploy your new chat app to Netlify you'll need to:
7386

7487
1. Create a [GitHub account](https://github.com/) (if you don't already have one)
7588
2. [Push your app to a GitHub repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-new-repository)
76-
3. [Create a Vercel account](https://vercel.com/signup)
77-
4. Create a new Vercel app and import your app from your GitHub repository. (This will require you to authorise Vercel to use your GitHub account)
78-
5. Add your `ABLY_API_KEY` as an environment variable
89+
3. [Create a Netlify account](https://netlify.com/signup)
90+
4. Create a new Netlify site and import your app from your GitHub repository. (This will require you to authorize Netlify to use your GitHub account)
91+
5. Add your `ABLY_API_KEY` as an environment variable in the Netlify site settings
7992
6. Watch your app deploy
8093
7. Visit the newly created URL in your browser!
8194

app/api/route.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

app/favicon.ico

25.3 KB
Binary file not shown.

app/layout.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/layout.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import './globals.css';
2+
import React from 'react';
3+
import { Metadata } from 'next';
4+
5+
export const metadata: Metadata = {
6+
title: 'Next.js',
7+
description: 'Generated by Next.js',
8+
};
9+
10+
export default function RootLayout({ children }: { children: React.ReactNode }) {
11+
return (
12+
<html lang="en">
13+
<body>{children}</body>
14+
</html>
15+
);
16+
}

app/page.module.css

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
.page {
2+
--gray-rgb: 0, 0, 0;
3+
--gray-alpha-200: rgba(var(--gray-rgb), 0.08);
4+
--gray-alpha-100: rgba(var(--gray-rgb), 0.05);
5+
6+
--button-primary-hover: #383838;
7+
--button-secondary-hover: #f2f2f2;
8+
9+
display: grid;
10+
grid-template-rows: 20px 1fr 20px;
11+
align-items: center;
12+
justify-items: center;
13+
min-height: 100svh;
14+
padding: 80px;
15+
gap: 64px;
16+
font-family: var(--font-geist-sans);
17+
}
18+
19+
@media (prefers-color-scheme: dark) {
20+
.page {
21+
--gray-rgb: 255, 255, 255;
22+
--gray-alpha-200: rgba(var(--gray-rgb), 0.145);
23+
--gray-alpha-100: rgba(var(--gray-rgb), 0.06);
24+
25+
--button-primary-hover: #ccc;
26+
--button-secondary-hover: #1a1a1a;
27+
}
28+
}
29+
30+
.main {
31+
display: flex;
32+
flex-direction: column;
33+
gap: 32px;
34+
grid-row-start: 2;
35+
}
36+
37+
.main ol {
38+
font-family: var(--font-geist-mono);
39+
padding-left: 0;
40+
margin: 0;
41+
font-size: 14px;
42+
line-height: 24px;
43+
letter-spacing: -0.01em;
44+
list-style-position: inside;
45+
}
46+
47+
.main li:not(:last-of-type) {
48+
margin-bottom: 8px;
49+
}
50+
51+
.main code {
52+
font-family: inherit;
53+
background: var(--gray-alpha-100);
54+
padding: 2px 4px;
55+
border-radius: 4px;
56+
font-weight: 600;
57+
}
58+
59+
.ctas {
60+
display: flex;
61+
gap: 16px;
62+
}
63+
64+
.ctas a {
65+
appearance: none;
66+
border-radius: 128px;
67+
height: 48px;
68+
padding: 0 20px;
69+
border: none;
70+
border: 1px solid transparent;
71+
transition:
72+
background 0.2s,
73+
color 0.2s,
74+
border-color 0.2s;
75+
cursor: pointer;
76+
display: flex;
77+
align-items: center;
78+
justify-content: center;
79+
font-size: 16px;
80+
line-height: 20px;
81+
font-weight: 500;
82+
}
83+
84+
a.primary {
85+
background: var(--foreground);
86+
color: var(--background);
87+
gap: 8px;
88+
}
89+
90+
a.secondary {
91+
border-color: var(--gray-alpha-200);
92+
min-width: 158px;
93+
}
94+
95+
.footer {
96+
grid-row-start: 3;
97+
display: flex;
98+
gap: 24px;
99+
}
100+
101+
.footer a {
102+
display: flex;
103+
align-items: center;
104+
gap: 8px;
105+
}
106+
107+
.footer img {
108+
flex-shrink: 0;
109+
}
110+
111+
/* Enable hover only on non-touch devices */
112+
@media (hover: hover) and (pointer: fine) {
113+
a.primary:hover {
114+
background: var(--button-primary-hover);
115+
border-color: transparent;
116+
}
117+
118+
a.secondary:hover {
119+
background: var(--button-secondary-hover);
120+
border-color: transparent;
121+
}
122+
123+
.footer a:hover {
124+
text-decoration: underline;
125+
text-underline-offset: 4px;
126+
}
127+
}
128+
129+
@media (max-width: 600px) {
130+
.page {
131+
padding: 32px;
132+
padding-bottom: 80px;
133+
}
134+
135+
.main {
136+
align-items: center;
137+
}
138+
139+
.main ol {
140+
text-align: center;
141+
}
142+
143+
.ctas {
144+
flex-direction: column;
145+
}
146+
147+
.ctas a {
148+
font-size: 14px;
149+
height: 40px;
150+
padding: 0 16px;
151+
}
152+
153+
a.secondary {
154+
min-width: auto;
155+
}
156+
157+
.footer {
158+
flex-wrap: wrap;
159+
align-items: center;
160+
justify-content: center;
161+
}
162+
}
163+
164+
@media (prefers-color-scheme: dark) {
165+
.logo {
166+
filter: invert();
167+
}
168+
}

0 commit comments

Comments
 (0)