replace tunnel middleware with refactored version

- Remove trailing slashes from tunnel/static prefixes.
- Add flag and flag check to determine when to stop processing the request.