@@ -14,9 +14,9 @@ import { RegistryProxy } from "~/v3/registryProxy.server";
14
14
15
15
const app = express ( ) ;
16
16
17
- // if (process.env.DISABLE_COMPRESSION !== "1") {
18
- // app.use(compression());
19
- // }
17
+ if ( process . env . DISABLE_COMPRESSION !== "1" ) {
18
+ app . use ( compression ( ) ) ;
19
+ }
20
20
21
21
// http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header
22
22
app . disable ( "x-powered-by" ) ;
@@ -73,63 +73,15 @@ if (process.env.HTTP_SERVER_DISABLED !== "true") {
73
73
next ( ) ;
74
74
} ) ;
75
75
76
- app . post ( "/realtime/v1/streams/express/test" , async ( req , res ) => {
77
- // Ensure the request is a readable stream
78
- const { method, headers } = req ;
79
- console . log ( "Inside /realtime/v1/streams/express/test" ) ;
80
-
81
- if ( method !== "POST" ) {
82
- return res . status ( 405 ) . send ( "Method Not Allowed" ) ;
83
- }
76
+ app . use ( ( req , res , next ) => {
77
+ // Generate a unique request ID for each request
78
+ const requestId = nanoid ( ) ;
84
79
85
- // Set encoding to UTF-8 to read string data
86
- req . setEncoding ( "utf8" ) ;
87
-
88
- let buffer = "" ;
89
-
90
- try {
91
- req . on ( "data" , ( chunk ) => {
92
- buffer += chunk ;
93
- const lines = buffer . split ( "\n" ) ;
94
- buffer = lines . pop ( ) || "" ;
95
-
96
- for ( const line of lines ) {
97
- if ( line . trim ( ) ) {
98
- const data = JSON . parse ( line ) ;
99
- console . log ( `${ new Date ( ) . toISOString ( ) } Received data:` , data ) ;
100
- // You can process each data chunk as needed
101
- }
102
- }
103
- } ) ;
104
-
105
- req . on ( "end" , ( ) => {
106
- if ( buffer ) {
107
- const data = JSON . parse ( buffer ) ;
108
- console . log ( `${ new Date ( ) . toISOString ( ) } Received data at end:` , data ) ;
109
- // You can process the remaining data as needed
110
- }
111
- res . status ( 200 ) . send ( ) ; // Send a success response
112
- } ) ;
113
-
114
- req . on ( "error" , ( error ) => {
115
- console . error ( "Error processing stream:" , error ) ;
116
- res . status ( 500 ) . send ( "Internal Server Error" ) ;
117
- } ) ;
118
- } catch ( error ) {
119
- console . error ( "Error processing stream:" , error ) ;
120
- res . status ( 500 ) . send ( "Internal Server Error" ) ;
121
- }
80
+ runWithHttpContext ( { requestId, path : req . url , host : req . hostname , method : req . method } , next ) ;
122
81
} ) ;
123
82
124
- // app.use((req, res, next) => {
125
- // // Generate a unique request ID for each request
126
- // const requestId = nanoid();
127
-
128
- // runWithHttpContext({ requestId, path: req.url, host: req.hostname, method: req.method }, next);
129
- // });
130
-
131
83
if ( process . env . DASHBOARD_AND_API_DISABLED !== "true" ) {
132
- // app.use(apiRateLimiter);
84
+ app . use ( apiRateLimiter ) ;
133
85
134
86
app . all (
135
87
"*" ,
0 commit comments