Skip to content

Commit 1ce58cb

Browse files
author
v1rtl
committed
chore: update some examples
1 parent 81a05a4 commit 1ce58cb

File tree

12 files changed

+1072
-89
lines changed

12 files changed

+1072
-89
lines changed

examples/file-upload/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
"private": true,
44
"dependencies": {
55
"@tinyhttp/app": "workspace:*",
6-
"formidable": "^3.2.5"
6+
"formidable": "^3.5.0"
77
},
88
"type": "module",
99
"scripts": {
1010
"start": "node index.js"
11+
},
12+
"devDependencies": {
13+
"@types/formidable": "^3.4.0"
1114
}
1215
}

examples/graphql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ node index.js
1717
Open [GraphiQL](http://localhost:3000/graphql) in the browser, or try with `curl`:
1818

1919
```sh
20-
curl 'http://localhost:3000/graphql?query=%23%20Welcome%20to%20GraphiQL%0A%23%0A%23%20GraphiQL%20is%20an%20in-browser%20tool%20for%20writing%2C%20validating%2C%20and%0A%23%20testing%20GraphQL%20queries.%0A%23%0A%23%20Type%20queries%20into%20this%20side%20of%20the%20screen%2C%20and%20you%20will%20see%20intelligent%0A%23%20typeaheads%20aware%20of%20the%20current%20GraphQL%20type%20schema%20and%20live%20syntax%20and%0A%23%20validation%20errors%20highlighted%20within%20the%20text.%0A%23%0A%23%20GraphQL%20queries%20typically%20start%20with%20a%20%22%7B%22%20character.%20Lines%20that%20start%0A%23%20with%20a%20%23%20are%20ignored.%0A%23%0A%23%20An%20example%20GraphQL%20query%20might%20look%20like%3A%0A%23%0A%23%20%20%20%20%20%7B%0A%23%20%20%20%20%20%20%20field(arg%3A%20%22value%22)%20%7B%0A%23%20%20%20%20%20%20%20%20%20subField%0A%23%20%20%20%20%20%20%20%7D%0A%23%20%20%20%20%20%7D%0A%23%0A%23%20Keyboard%20shortcuts%3A%0A%23%0A%23%20%20Prettify%20Query%3A%20%20Shift-Ctrl-P%20(or%20press%20the%20prettify%20button%20above)%0A%23%0A%23%20%20%20%20%20Merge%20Query%3A%20%20Shift-Ctrl-M%20(or%20press%20the%20merge%20button%20above)%0A%23%0A%23%20%20%20%20%20%20%20Run%20Query%3A%20%20Ctrl-Enter%20(or%20press%20the%20play%20button%20above)%0A%23%0A%23%20%20%20Auto%20Complete%3A%20%20Ctrl-Space%20(or%20just%20start%20typing)%0A%23%0A%0A%7B%0A%20%20hello%0A%7D'
20+
curl 'http://localhost:3000/graphql?query={%0A++hello%0A}'
2121
```

examples/graphql/index.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { App } from '@tinyhttp/app'
22
import graphql from 'graphql'
3-
import expressGraphQL from 'express-graphql'
3+
import {createHandler} from 'graphql-http/lib/use/http'
44

55
const app = new App()
66
const port = parseInt(process.env.PORT) || 3000
@@ -15,13 +15,8 @@ const rootValue = {
1515
hello: () => 'Hello world!'
1616
}
1717

18-
app.use(
19-
'/graphql',
20-
expressGraphQL.graphqlHTTP({
21-
schema,
22-
graphiql: { headerEditorEnabled: true },
23-
rootValue
24-
})
25-
)
18+
const handler = createHandler({ schema, rootValue })
19+
20+
app.use('/graphql', handler)
2621

2722
app.listen(port, () => console.log(`Listening on http://localhost:${port}`))

examples/graphql/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"private": true,
55
"dependencies": {
66
"@tinyhttp/app": "workspace:*",
7-
"express-graphql": "^0.12.0",
8-
"graphql": "^16.6.0"
7+
"graphql": "^16.7.1",
8+
"graphql-http": "^1.21.0"
99
},
1010
"scripts": {
1111
"start": "node index.js"

examples/prisma-graphql/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
"name": "tinyhttp-prisma-graphql",
44
"type": "module",
55
"scripts": {
6-
"start": "node index.js"
6+
"start": "node index.js",
7+
"postinstall": "prisma generate"
78
},
89
"dependencies": {
9-
"@prisma/client": "3.5.0",
10+
"@prisma/client": "5.1.1",
1011
"@tinyhttp/app": "workspace:*",
1112
"express-graphql": "^0.12.0",
12-
"graphql": "^16.0.1"
13+
"graphql": "^16.7.1"
14+
},
15+
"devDependencies": {
16+
"prisma": "^5.1.1"
1317
}
1418
}

examples/prisma/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"postinstall": "prisma generate"
88
},
99
"dependencies": {
10-
"@prisma/client": "4.11.0",
10+
"@prisma/client": "5.1.1",
1111
"@tinyhttp/app": "workspace:*",
12-
"milliparsec": "^2.2.2"
12+
"milliparsec": "^2.3.0"
1313
},
1414
"devDependencies": {
15-
"prisma": "^4.11.0"
15+
"prisma": "^5.1.1"
1616
}
1717
}

examples/validator/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"type": "module",
55
"dependencies": {
66
"@tinyhttp/app": "workspace:*",
7-
"fastest-validator": "^1.16.0",
8-
"milliparsec": "^2.2.2"
7+
"fastest-validator": "^1.17.0",
8+
"milliparsec": "^2.3.0"
99
},
1010
"scripts": {
1111
"start": "node index.js"

examples/vue-ssr/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"type": "module",
55
"dependencies": {
66
"@tinyhttp/app": "workspace:*",
7-
"sirv": "^2.0.2",
8-
"vue": "^3.2.47",
7+
"sirv": "^2.0.3",
8+
"vue": "^3.3.4",
99
"vue-server-renderer": "^2.7.14"
1010
},
1111
"scripts": {

examples/ws/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ node index.js
1717
now open a few terminal windows and send messages:
1818

1919
```sh
20-
$ wscat -c http://localhost:3000/chat
21-
# > hello
20+
$ wscat -c ws://localhost:3000/chat
21+
# > hello there
2222
# < hello
2323
# < someone else sent this
2424
# >

examples/ws/index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
import { App } from '@tinyhttp/app'
2-
import { tinyws } from 'tinyws'
1+
import { App, } from '@tinyhttp/app'
2+
import { tinyws, } from 'tinyws'
33

44
const app = new App()
55

66
app.use(tinyws())
77

8-
app.use('/hmr', async (req, res) => {
8+
let connections = []
9+
10+
app.use('/chat', async (req) => {
911
if (req.ws) {
1012
const ws = await req.ws()
1113

12-
return ws.send('hello there')
13-
} else {
14-
res.send('Hello from HTTP!')
14+
connections.push(ws)
15+
16+
ws.on('message', (message) => {
17+
console.log('Received message:', message.toString())
18+
19+
// broadcast
20+
connections.forEach((socket) => socket.send(message))
21+
})
22+
23+
ws.on('close', () => (connections = connections.filter((conn) => (conn === ws ? false : true))))
1524
}
1625
})
1726

18-
app.listen(3000)
27+
app.listen(3000)

0 commit comments

Comments
 (0)