@@ -2,7 +2,7 @@ import Fastify from 'fastify';
22import fastifyMiddie from '@fastify/middie' ;
33import fastifyHttpProxy from '@fastify/http-proxy' ;
44import { createBareServer } from '@tomphttp/bare-server-node' ;
5- import createRammerhead from "@rubynetwork/rammerhead/src/server/index.js " ;
5+ import { createRammerhead , shouldRouteRh , routeRhRequest , routeRhUpgrade } from "@rubynetwork/rammerhead" ;
66import { createServer } from 'http' ;
77import path from 'path' ;
88const __dirname = path . resolve ( ) ;
@@ -11,40 +11,31 @@ import wisp from 'wisp-server-node';
1111import fastifyCaching from '@fastify/caching' ;
1212let nodePort = process . argv . find ( ( arg ) => arg . startsWith ( '--node-port' ) ) . split ( '=' ) [ 1 ] || 9294 ;
1313const bare = createBareServer ( '/bare/' ) ;
14- const rh = createRammerhead ( ) ;
15- const rammerheadScopes = [ "/rammerhead.js" , "/hammerhead.js" , "/transport-worker.js" , "/task.js" , "/iframe-task.js" , "/worker-hammerhead.js" , "/messaging" , "/sessionexists" , "/deletesession" , "/newsession" , "/editsession" , "/needpassword" , "/syncLocalStorage" , "/api/shuffleDict" , "/mainport" ] ;
16- const rammerheadSession = / ^ \/ [ a - z 0 - 9 ] { 32 } / ;
17- function shouldRouteRh ( req ) {
18- const url = new URL ( req . url , "http://0.0.0.0" ) ;
19- return ( rammerheadScopes . includes ( url . pathname ) || rammerheadSession . test ( url . pathname ) )
20- }
21- function routeRhRequest ( req , res ) { rh . emit ( "request" , req , res ) }
22- function routeRhUpgrade ( req , socket , head ) { rh . emit ( "upgrade" , req , socket , head ) }
14+ const rh = createRammerhead ( {
15+ reverseProxy : true ,
16+ disableHttp2 : false ,
17+ disableLocalStorageSync : false ,
18+ logLevel : 'debug'
19+ } ) ;
2320
2421const proxyHandler = ( handler , opts ) => {
2522 return createServer ( ) . on ( 'request' , ( req , res ) => {
26- if ( req . url . startsWith ( '/rammer' ) ) {
27- req . url = req . url . replace ( '/rammer' , '' ) ;
28- }
2923 if ( bare . shouldRoute ( req ) ) {
3024 bare . routeRequest ( req , res ) ;
3125 }
3226 else if ( shouldRouteRh ( req ) ) {
33- routeRhRequest ( req , res ) ;
27+ routeRhRequest ( rh , req , res ) ;
3428 }
3529 else {
3630 handler ( req , res ) ;
3731 }
3832 } )
3933 . on ( 'upgrade' , ( req , socket , head ) => {
40- if ( req . url . startsWith ( '/rammer' ) ) {
41- req . url = req . url . replace ( '/rammer' , '' ) ;
42- }
4334 if ( bare . shouldRoute ( req ) ) {
4435 bare . routeUpgrade ( req , socket , head ) ;
4536 }
4637 else if ( shouldRouteRh ( req ) ) {
47- routeRhUpgrade ( req , socket , head ) ;
38+ routeRhUpgrade ( rh , req , socket , head ) ;
4839 }
4940 else if ( req . url . endsWith ( '/wisp/' ) ) {
5041 wisp . routeRequest ( req , socket , head ) ;
0 commit comments