Skip to content

Commit 89e931d

Browse files
authored
Merge branch 'main' into patch-1
2 parents 98f06be + 6b02bef commit 89e931d

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:14.15.3
2+
3+
RUN mkdir -p /opt/notes-app
4+
WORKDIR /opt/notes-app
5+
6+
COPY package.json package-lock.json ./
7+
8+
RUN npm install
9+
10+
CMD ["npm", "run", "start"]

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Server Components are an experimental feature and **are not ready for adoption**
2323

2424
## Setup
2525

26+
You will need to have nodejs >=14.9.0 in order to run this demo. [Node 14 LTS](https://nodejs.org/en/about/releases/) is a good choice!
27+
2628
```
2729
npm install
2830
npm start
@@ -34,10 +36,24 @@ Then open http://localhost:4000.
3436

3537
The app won't work until you set up the database, as described below.
3638

39+
<details>
40+
<summary>Setup with Docker</summary>
41+
<p>You can also start dev build of the app by using docker-compose.</p>
42+
<p>Make sure you have docker and docker-compose installed then run:</p>
43+
<pre><code>docker-compose up</code></pre>
44+
<h4>Running seed script</h4>
45+
<p>1. Run containers in the detached mode</p>
46+
<pre><code>docker-compose up -d</code></pre>
47+
<p>2. Run seed script</p>
48+
<pre><code>docker-compose exec notes-app npm run seed</code></pre>
49+
</details>
50+
3751
## DB Setup
3852

3953
This demo uses Postgres. First, follow its [installation link](https://wiki.postgresql.org/wiki/Detailed_installation_guides) for your platform.
4054

55+
Alternatively, you can check out this [fork](https://github.com/pomber/server-components-demo/) which will let you run the demo app without needing a database. However, you won't be able to execute SQL queries (but fetch should still work).
56+
4157
The below example will set up the database for this app, assuming that you have a UNIX-like platform:
4258

4359
### Step 1. Create the Database
@@ -96,7 +112,11 @@ This demo is built on top of our Webpack plugin, but this is not how we envision
96112
- Search for any title. With the search text still in the search input, create a new note with a title matching the search text. What happens?
97113
- Search while on Slow 3G, observe the inline loading indicator.
98114
- Switch between two notes back and forth. Observe we don't send new responses next time we switch them again.
99-
- Uncomment the `fetch('http://localhost:4000/sleep/....')` calls in `NoteServer.js` and/or `NoteList.server.js` to introduce an artificial delay and trigger Suspense.
115+
- Uncomment the `fetch('http://localhost:4000/sleep/....')` call in `Note.server.js` or `NoteList.server.js` to introduce an artificial delay and trigger Suspense.
116+
- If you only uncomment it in `Note.server.js`, you'll see the fallback every time you open a note.
117+
- If you only uncomment it in `NoteList.server.js`, you'll see the list fallback on first page load.
118+
- If you uncomment it in both, it won't be very interesting because we have nothing new to show until they both respond.
119+
- Add a new Server Component and place it above the search bar in `App.server.js`. Import `db` from `db.server` and use `db.query()` from it to get the number of notes. Oberserve what happens when you add or delete a note.
100120

101121
## Built by (A-Z)
102122

docker-compose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: "3.8"
2+
services:
3+
postgres:
4+
image: postgres:13
5+
environment:
6+
POSTGRES_USER: admin
7+
POSTGRES_PASSWORD: admin
8+
POSTGRES_DB: notesapi
9+
ports:
10+
- '5432:5432'
11+
volumes:
12+
- ./scripts/init_db.sh:/docker-entrypoint-initdb.d/init_db.sh
13+
- db:/var/lib/postgresql/data
14+
15+
notes-app:
16+
build:
17+
context: .
18+
depends_on:
19+
- postgres
20+
ports:
21+
- '4000:4000'
22+
network_mode: host
23+
volumes:
24+
- ./notes:/opt/notes-app/notes
25+
- ./public:/opt/notes-app/public
26+
- ./scripts:/opt/notes-app/scripts
27+
- ./server:/opt/notes-app/server
28+
- ./src:/opt/notes-app/src
29+
- ./credentials.json:/opt/notes-app/credentials.json
30+
31+
volumes:
32+
db:

scripts/init_db.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -e
3+
4+
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
5+
CREATE ROLE notesadmin WITH LOGIN PASSWORD 'password';
6+
ALTER ROLE notesadmin WITH SUPERUSER;
7+
ALTER DATABASE notesapi OWNER TO notesadmin;
8+
9+
DROP TABLE IF EXISTS notes;
10+
CREATE TABLE notes (
11+
id SERIAL PRIMARY KEY,
12+
created_at TIMESTAMP NOT NULL,
13+
updated_at TIMESTAMP NOT NULL,
14+
title TEXT,
15+
body TEXT
16+
);
17+
EOSQL

0 commit comments

Comments
 (0)