File tree 1 file changed +4
-6
lines changed
1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -47,19 +47,17 @@ describe("update", () => {
47
47
48
48
// Checks if url matches /redirect/${number}
49
49
// with optional trailing slash
50
- let redirectSlashNumberRegExp = new RegExp ( / \/ r e d i r e c t \/ ( [ 0 - 9 ] + ) ( \/ ) ? $ / )
51
-
52
- if ( request . url . match ( redirectSlashNumberRegExp ) ) {
50
+ const match = request . url . match ( / \/ r e d i r e c t \/ ( [ 0 - 9 ] + ) \/ ? $ / )
51
+ if ( match ) {
53
52
if ( request . url === "/redirect/0" ) {
54
53
response . writeHead ( 200 )
55
54
return response . end ( "done" )
56
55
}
57
56
58
57
// Subtract 1 from the current redirect number
59
58
// i.e. /redirect/10 -> /redirect/9 -> /redirect/8
60
- const urlSplit = request . url . split ( "/" )
61
- const currentRedirectNumber = urlSplit [ urlSplit . length - 1 ]
62
- const newRedirectNumber = parseInt ( currentRedirectNumber ) - 1
59
+ const currentRedirectNumber = parseInt ( match [ 1 ] )
60
+ const newRedirectNumber = currentRedirectNumber - 1
63
61
64
62
response . writeHead ( 302 , "testing" , {
65
63
location : `/redirect/${ String ( newRedirectNumber ) } ` ,
You can’t perform that action at this time.
0 commit comments