|
1 | 1 | import { resolve, join } from 'path'
|
2 |
| -import { parse } from 'url' |
| 2 | +import { parse as parseUrl } from 'url' |
| 3 | +import { parse as parseQs } from 'querystring' |
3 | 4 | import fs from 'mz/fs'
|
4 | 5 | import http, { STATUS_CODES } from 'http'
|
5 | 6 | import {
|
@@ -33,12 +34,14 @@ export default class Server {
|
33 | 34 |
|
34 | 35 | getRequestHandler () {
|
35 | 36 | return (req, res, parsedUrl) => {
|
| 37 | + // Parse url if parsedUrl not provided |
36 | 38 | if (!parsedUrl) {
|
37 |
| - parsedUrl = parse(req.url, true) |
| 39 | + parsedUrl = parseUrl(req.url, true) |
38 | 40 | }
|
39 | 41 |
|
40 |
| - if (!parsedUrl.query) { |
41 |
| - throw new Error('Please provide a parsed url to `handle` as third parameter. See https://github.com/zeit/next.js#custom-server-and-routing for an example.') |
| 42 | + // Parse the querystring ourselves if the user doesn't handle querystring parsing |
| 43 | + if (typeof parsedUrl.query === 'string') { |
| 44 | + parsedUrl.query = parseQs(parsedUrl.query) |
42 | 45 | }
|
43 | 46 |
|
44 | 47 | return this.run(req, res, parsedUrl)
|
@@ -222,7 +225,7 @@ export default class Server {
|
222 | 225 | }
|
223 | 226 | }
|
224 | 227 |
|
225 |
| - async render404 (req, res, parsedUrl = parse(req.url, true)) { |
| 228 | + async render404 (req, res, parsedUrl = parseUrl(req.url, true)) { |
226 | 229 | const { pathname, query } = parsedUrl
|
227 | 230 | res.statusCode = 404
|
228 | 231 | return this.renderError(null, req, res, pathname, query)
|
|
0 commit comments