trpc-uwebsockets 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/package.json +1 -1
- package/test/index.spec.ts +16 -0
package/README.md
CHANGED
|
@@ -65,6 +65,12 @@ createUWebSocketsHandler(app, '/trpc', {
|
|
|
65
65
|
createContext,
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
/* dont crash on unknown request */
|
|
69
|
+
app.any('/*', (res) => {
|
|
70
|
+
res.writeStatus('404 NOT FOUND');
|
|
71
|
+
res.end();
|
|
72
|
+
});
|
|
73
|
+
|
|
68
74
|
app.listen('0.0.0.0', 8000, () => {
|
|
69
75
|
console.log('Server listening on http://localhost:8000');
|
|
70
76
|
});
|
package/package.json
CHANGED
package/test/index.spec.ts
CHANGED
|
@@ -123,6 +123,11 @@ async function startServer() {
|
|
|
123
123
|
res.end();
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
+
app.any('/*', (res) => {
|
|
127
|
+
res.writeStatus('404 NOT FOUND');
|
|
128
|
+
res.end();
|
|
129
|
+
});
|
|
130
|
+
|
|
126
131
|
const { socket } = await new Promise<{
|
|
127
132
|
socket: uWs.us_listen_socket;
|
|
128
133
|
}>((resolve) => {
|
|
@@ -225,7 +230,9 @@ test('setting cookies and headers', async () => {
|
|
|
225
230
|
'one=nom, two=nom%20nom'
|
|
226
231
|
);
|
|
227
232
|
expect(monsterRes.headers.get('x-spooked')).toEqual('true');
|
|
233
|
+
});
|
|
228
234
|
|
|
235
|
+
test('error handling', async () => {
|
|
229
236
|
const indexRes = await fetch(`http://localhost:${testPort}`);
|
|
230
237
|
expect(indexRes.status).toEqual(200);
|
|
231
238
|
|
|
@@ -239,4 +246,13 @@ test('setting cookies and headers', async () => {
|
|
|
239
246
|
`http://localhost:${testPort}/trpc/hello?input=${badInput}`
|
|
240
247
|
);
|
|
241
248
|
expect(badRes.status).toEqual(400);
|
|
249
|
+
|
|
250
|
+
const badPath = await fetch(
|
|
251
|
+
`http://localhost:${testPort}/trpc/nonexisting?input=${badInput}`
|
|
252
|
+
);
|
|
253
|
+
expect(badPath.status).toEqual(400);
|
|
254
|
+
|
|
255
|
+
const uncaught = await fetch(`http://localhost:${testPort}/badurl`);
|
|
256
|
+
|
|
257
|
+
expect(uncaught.status).toEqual(404);
|
|
242
258
|
});
|