-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add newsletter cta to cheat sheet
- Loading branch information
Showing
8 changed files
with
358 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
18.17.1 | ||
20.12.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import type * as Party from 'partykit/server' | ||
|
||
const CORS = { | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Methods': 'GET', | ||
'Access-Control-Allow-Headers': | ||
'Origin, X-Requested-With, Content-Type, Accept', | ||
} | ||
|
||
export default class Server implements Party.Server { | ||
constructor(readonly party: Party.Room) {} | ||
|
||
async onConnect(conn: Party.Connection, ctx: Party.ConnectionContext) { | ||
// A websocket just connected! | ||
console.log( | ||
`Connected: | ||
id: ${conn.id} | ||
room: ${this.party.id} | ||
url: ${new URL(ctx.request.url).pathname}`, | ||
) | ||
} | ||
|
||
messages: string[] = [] | ||
|
||
async onStart() { | ||
this.messages = (await this.party.storage.get<string[]>('messages')) ?? [] | ||
} | ||
|
||
async onRequest(req: Party.Request) { | ||
if (req.method === 'GET') { | ||
// For SSR, return the current presence of all connections | ||
// const users = [...this.party.getConnections()].reduce( | ||
// (acc, user) => ({...acc, [user.id]: this.getUser(user)}), | ||
// {}, | ||
// ) | ||
return Response.json({users: []}, {status: 200, headers: CORS}) | ||
} | ||
|
||
// respond to cors preflight requests | ||
if (req.method === 'OPTIONS') { | ||
return Response.json({ok: true}, {status: 200, headers: CORS}) | ||
} | ||
|
||
if (req.method === 'POST') { | ||
const messageBody: {requestId: string; body: string; name: string} = | ||
await req.json() | ||
|
||
this.party.broadcast(JSON.stringify(messageBody)) | ||
|
||
return new Response( | ||
`Party ${this.party.id} has received ${this.messages.length} messages`, | ||
) | ||
} | ||
|
||
return new Response('Method Not Allowed', {status: 405}) | ||
} | ||
|
||
onMessage(message: string, sender: Party.Connection) { | ||
// let's log the message | ||
console.log(`connection ${sender.id} sent message: ${message}`) | ||
// as well as broadcast it to all the other connections in the room... | ||
this.party.broadcast( | ||
`${sender.id}: ${message}`, | ||
// ...except for the connection it came from | ||
[sender.id], | ||
) | ||
} | ||
} | ||
|
||
Server satisfies Party.Worker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "epic-react", | ||
"main": "party/index.ts", | ||
"compatibilityDate": "2023-10-20", | ||
"team": "skillrecordings" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.