|
| 1 | +import { parse } from 'node:url'; |
1 | 2 | import { Connect, Identity, Inboxes, Messages, SpaceEvents, Utils } from '@graphprotocol/hypergraph';
|
2 | 3 | import { bytesToHex, randomBytes } from '@noble/hashes/utils.js';
|
3 | 4 | import cors from 'cors';
|
4 | 5 | import { Effect, Exit, Schema } from 'effect';
|
5 | 6 | import express, { type NextFunction, type Request, type Response } from 'express';
|
6 |
| -import { parse } from 'node:url'; |
7 | 7 | import WebSocket, { WebSocketServer } from 'ws';
|
8 | 8 | import { addAppIdentityToSpaces } from './handlers/add-app-identity-to-spaces.js';
|
9 | 9 | import { applySpaceEvent } from './handlers/applySpaceEvent.js';
|
@@ -70,26 +70,12 @@ app.use(cors());
|
70 | 70 |
|
71 | 71 | // Request timeout middleware
|
72 | 72 | app.use((req: Request, res: Response, next: NextFunction) => {
|
73 |
| - req.setTimeout(30000, () => { |
| 73 | + res.setTimeout(30000, () => { |
74 | 74 | res.status(408).json({ error: 'Request timeout' });
|
75 | 75 | });
|
76 | 76 | next();
|
77 | 77 | });
|
78 | 78 |
|
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 |
| - |
93 | 79 | app.get('/', (_req, res) => {
|
94 | 80 | res.send('Server is running (v0.0.10)');
|
95 | 81 | });
|
@@ -575,6 +561,20 @@ app.post('/accounts/:accountAddress/inboxes/:inboxId/messages', async (req, res)
|
575 | 561 | broadcastAccountInboxMessage({ accountAddress, inboxId, message: createdMessage });
|
576 | 562 | });
|
577 | 563 |
|
| 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 | + |
578 | 578 | const server = app.listen(PORT, () => {
|
579 | 579 | console.log(`Listening on port ${PORT}`);
|
580 | 580 | });
|
|
0 commit comments