 			for versionNumber, version of _package.versions
 				writer.startElement 'version'
 				writer.writeAttribute 'name', versionNumber
-
+				
 				# we do not support authentification
 				writer.writeAttribute 'accessible', "true"
 				writer.writeAttribute 'isCritical', if (/pl/i.test versionNumber) then "true" else "false"

										currentVersion = { }
										currentVersion.versionnumber = versionNumber
										currentVersion.license = versionPackageXml.package.packageinformation[0].license?[0]

										# the tar file is incorrectly named -> abort
										if (currentVersion.versionnumber.replace new RegExp(' ', 'g'), '_') isnt path.basename versionFile, '.tar'
											fileCallback "version number does not match file (#{currentVersion.versionnumber.replace ' ', '_'} != #{path.basename versionFile, '.tar'})"

		writer.writeComment "This list was presented by Tims Package Server #{serverVersion}"
		do writer.endElement
		do writer.endDocument
	res.end (do writer.toString).replace /\{\{packageServerHost\}\}/g, host

# package download requested
app.all /^\/([a-z0-9_-]+\.[a-z0-9_-]+(?:\.[a-z0-9_-]+)+)\/([0-9]+\.[0-9]+\.[0-9]+(?:_(?:a|alpha|b|beta|d|dev|rc|pl)_[0-9]+)?)\/?(?:\?.*)?$/i, (req, res) ->
	res.attachment "#{req.params[0]}_#{req.params[1]}.tar"
	res.sendfile "#{config.packageFolder}/#{req.params[0]}/#{req.params[1]}.tar", (err)  ->
		if err?
			res.statusCode = 404
			do res.end

# allow download without version number
app.all /^\/([a-z0-9_-]+\.[a-z0-9_-]+(?:\.[a-z0-9_-]+)+)\/?(?:\?.*)?$/i, (req, res) ->
	res.attachment "#{req.params[0]}.tar"
	res.sendfile "#{config.packageFolder}/#{req.params[0]}/latest", (err) ->
		if err?
			res.statusCode = 404
			do res.end

# manual update via {{packageServerHost}}/update
if config.enableManualUpdate
	app.get '/update', (req, res) ->
		logger.log "info", 'Manual update was requested'
		readPackages ->
			res.redirect 303, config.basePath ? "#{req.protocol}://#{req.header 'host'}/"

# throw 404 on any unknown route
app.all '*', (req, res) ->
	res.statusCode = 404
	do res.end

# Once the package list was successfully scanned once bind to the port
readPackages ->
	app.listen config.port
	
