 		# Prepare
 		docpad = @
 
-		# If we are generating then wait until generation is complete before continuing
-		if docpad.lastGenerate is null or docpad.generating is true
+		# If we have not performed a generation yet then wait until the initial generation has completed
+		if docpad.generateEnded is null # or docpad.generating is true
 			docpad.once 'generateAfter', ->
 				return docpad.serverMiddlewareRouter(req,res,next)
 			return @
 
 		# Prepare
+		database = docpad.getDatabaseCache()
 		cleanUrl = req.url.replace(/\?.*/,'')
-		file = docpad.getFileByUrl(req.url) or docpad.getFileByUrl(cleanUrl)
+		file = docpad.getFileByUrl(req.url,{collection:database}) or docpad.getFileByUrl(cleanUrl,{collection:database})
 		return next()  if file? is false
 
 		# Check if we are the desired url


		# Update generating flag
		docpad.generating = false
		collection.each (file) ->
			for url in file.get('urls')
				docpad.filesByUrl[url] = file.cid
		docpad.filesByUrlCache = docpad.filesByUrl

		# Fire plugins
		docpad.emitSync 'generateAfter', server:docpad.getServer(), (err) ->
			return next(err)  if err

			# Log generated
			seconds = (new Date() - docpad.lastGenerate) / 1000
			howMany =
				if collection is database
					"all #{collection.length}"

					message = "You have files that share the same relativePath, this will cause unexpected results, please rename one of these files:\n  #{modelPath}\n  #{existingModelPath}"
					docpad.warn(message)
			)
		@locales = extendr.dereference(@locales)
		@userConfig = extendr.dereference(@userConfig)
		@initialConfig = extendr.dereference(@initialConfig)
