Update middleware.js

Fix the "Cannot read property '1' of null" exception when the extension is followed by a slash.