Skip to content

Commit

Permalink
Fix a trailing slash with query strings (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltask authored and leo committed Feb 14, 2017
1 parent ba834f6 commit 9cb67ed
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Native
const path = require('path')
const {parse} = require('url')
const {parse, format} = require('url')

// Packages
const micro = require('micro')
Expand Down Expand Up @@ -79,8 +79,10 @@ module.exports = async (req, res, flags, current, ignoredFiles) => {
if (relatedExists && await pathType.dir(related)) {
// Normalize path to trailing slash
// Otherwise problems like #70 will occur
if (req.url.substr(-1) !== '/') {
const newPath = req.url + '/'
const url = parse(req.url)
if (url.pathname.substr(-1) !== '/') {
url.pathname += '/'
const newPath = format(url)

res.writeHead(302, {
Location: newPath
Expand Down

0 comments on commit 9cb67ed

Please sign in to comment.