Skip to content

Commit 4833f56

Browse files
committed
follow AI recommendations
1 parent 0cbcfd6 commit 4833f56

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

apps/server/src/index.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { parse } from 'node:url';
12
import { Connect, Identity, Inboxes, Messages, SpaceEvents, Utils } from '@graphprotocol/hypergraph';
23
import { bytesToHex, randomBytes } from '@noble/hashes/utils.js';
34
import cors from 'cors';
45
import { Effect, Exit, Schema } from 'effect';
56
import express, { type NextFunction, type Request, type Response } from 'express';
6-
import { parse } from 'node:url';
77
import WebSocket, { WebSocketServer } from 'ws';
88
import { addAppIdentityToSpaces } from './handlers/add-app-identity-to-spaces.js';
99
import { applySpaceEvent } from './handlers/applySpaceEvent.js';
@@ -70,26 +70,12 @@ app.use(cors());
7070

7171
// Request timeout middleware
7272
app.use((req: Request, res: Response, next: NextFunction) => {
73-
req.setTimeout(30000, () => {
73+
res.setTimeout(30000, () => {
7474
res.status(408).json({ error: 'Request timeout' });
7575
});
7676
next();
7777
});
7878

79-
// Global error handling middleware
80-
app.use((error: Error, req: Request, res: Response, next: NextFunction) => {
81-
console.error('Unhandled error:', error);
82-
res.status(500).json({
83-
error: 'Internal server error',
84-
message: process.env.NODE_ENV === 'development' ? error.message : 'Something went wrong',
85-
});
86-
});
87-
88-
// 404 handler
89-
app.use('*', (req: Request, res: Response) => {
90-
res.status(404).json({ error: 'Route not found' });
91-
});
92-
9379
app.get('/', (_req, res) => {
9480
res.send('Server is running (v0.0.10)');
9581
});
@@ -575,6 +561,20 @@ app.post('/accounts/:accountAddress/inboxes/:inboxId/messages', async (req, res)
575561
broadcastAccountInboxMessage({ accountAddress, inboxId, message: createdMessage });
576562
});
577563

564+
// Global error handling middleware
565+
app.use((error: Error, req: Request, res: Response, next: NextFunction) => {
566+
console.error('Unhandled error:', error);
567+
res.status(500).json({
568+
error: 'Internal server error',
569+
message: process.env.NODE_ENV === 'development' ? error.message : 'Something went wrong',
570+
});
571+
});
572+
573+
// 404 handler
574+
app.use('*', (req: Request, res: Response) => {
575+
res.status(404).json({ error: 'Route not found' });
576+
});
577+
578578
const server = app.listen(PORT, () => {
579579
console.log(`Listening on port ${PORT}`);
580580
});

0 commit comments

Comments
 (0)