@@ -79,51 +79,48 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
79
79
app . router . use ( common )
80
80
app . wsRouter . use ( common )
81
81
82
- app . router . use ( async ( req , res , next ) => {
82
+ app . router . use ( / . * / , async ( req , res , next ) => {
83
83
// If we're handling TLS ensure all requests are redirected to HTTPS.
84
84
// TODO: This does *NOT* work if you have a base path since to specify the
85
85
// protocol we need to specify the whole path.
86
86
if ( args . cert && ! ( req . connection as tls . TLSSocket ) . encrypted ) {
87
87
return res . redirect ( `https://${ req . headers . host } ${ req . originalUrl } ` )
88
88
}
89
+ next ( )
90
+ } )
89
91
90
- // Return security.txt.
91
- if ( req . originalUrl === "/security.txt" || req . originalUrl === "/.well-known/security.txt" ) {
92
- const resourcePath = path . resolve ( rootPath , "src/browser/security.txt" )
93
- res . set ( "Content-Type" , getMediaMime ( resourcePath ) )
94
- return res . send ( await fs . readFile ( resourcePath ) )
95
- }
96
-
97
- // Return robots.txt.
98
- if ( req . originalUrl === "/robots.txt" ) {
99
- const resourcePath = path . resolve ( rootPath , "src/browser/robots.txt" )
100
- res . set ( "Content-Type" , getMediaMime ( resourcePath ) )
101
- return res . send ( await fs . readFile ( resourcePath ) )
102
- }
92
+ app . router . get ( [ "/security.txt" , "/.well-known/security.txt" ] , async ( _ , res ) => {
93
+ const resourcePath = path . resolve ( rootPath , "src/browser/security.txt" )
94
+ res . set ( "Content-Type" , getMediaMime ( resourcePath ) )
95
+ res . send ( await fs . readFile ( resourcePath ) )
96
+ } )
103
97
104
- next ( )
98
+ app . router . get ( "/robots.txt" , async ( _ , res ) => {
99
+ const resourcePath = path . resolve ( rootPath , "src/browser/robots.txt" )
100
+ res . set ( "Content-Type" , getMediaMime ( resourcePath ) )
101
+ res . send ( await fs . readFile ( resourcePath ) )
105
102
} )
106
103
107
104
app . router . use ( "/" , domainProxy . router )
108
105
app . wsRouter . use ( "/" , domainProxy . wsRouter . router )
109
106
110
- app . router . all ( "/proxy/:port/:path(.*)? " , async ( req , res ) => {
107
+ app . router . all ( "/proxy/:port{/*path} " , async ( req , res ) => {
111
108
await pathProxy . proxy ( req , res )
112
109
} )
113
- app . wsRouter . get ( "/proxy/:port/:path(.*)? " , async ( req ) => {
114
- await pathProxy . wsProxy ( req as WebsocketRequest )
110
+ app . wsRouter . get ( "/proxy/:port{/*path} " , async ( req ) => {
111
+ await pathProxy . wsProxy ( req as unknown as WebsocketRequest )
115
112
} )
116
113
// These two routes pass through the path directly.
117
114
// So the proxied app must be aware it is running
118
115
// under /absproxy/<someport>/
119
- app . router . all ( "/absproxy/:port/:path(.*)? " , async ( req , res ) => {
116
+ app . router . all ( "/absproxy/:port{/*path} " , async ( req , res ) => {
120
117
await pathProxy . proxy ( req , res , {
121
118
passthroughPath : true ,
122
119
proxyBasePath : args [ "abs-proxy-base-path" ] ,
123
120
} )
124
121
} )
125
- app . wsRouter . get ( "/absproxy/:port/:path(.*)? " , async ( req ) => {
126
- await pathProxy . wsProxy ( req as WebsocketRequest , {
122
+ app . wsRouter . get ( "/absproxy/:port{/*path} " , async ( req ) => {
123
+ await pathProxy . wsProxy ( req as unknown as WebsocketRequest , {
127
124
passthroughPath : true ,
128
125
proxyBasePath : args [ "abs-proxy-base-path" ] ,
129
126
} )
0 commit comments