Skip to content

Commit

Permalink
refactor(middleware): handle paths as URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
falsandtru committed May 10, 2020
1 parent bcaae16 commit 981f4fc
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,31 +162,27 @@ function createKarmaMiddleware (

const scriptTags = []
for (const file of files.included) {
let filePath = file.path
const urlPath = file.isUrl
? file.path
: requestUrl === '/context.html'
? filePathToUrlPath(file.path, basePath, urlRoot, proxyPath) + '?' + file.sha
: filePathToUrlPath(file.path, basePath, urlRoot, proxyPath)
const fileType = helper.getFileType(file)

if (helper.isDefined(fileType) && !FILE_TYPES.includes(fileType)) {
log.warn(`Invalid file type (${fileType}), defaulting to js.`)
}

if (!file.isUrl) {
filePath = filePathToUrlPath(filePath, basePath, urlRoot, proxyPath)

if (requestUrl === '/context.html') {
filePath += '?' + file.sha
}
}

if (fileType === 'css') {
scriptTags.push(`<link type="text/css" href="${filePath}" rel="stylesheet">`)
scriptTags.push(`<link type="text/css" href="${urlPath}" rel="stylesheet">`)
} else if (fileType === 'dom') {
scriptTags.push(file.content)
} else if (fileType === 'html') {
scriptTags.push(`<link href="${filePath}" rel="import">`)
scriptTags.push(`<link href="${urlPath}" rel="import">`)
} else {
const scriptType = (SCRIPT_TYPE[fileType] || 'text/javascript')
const crossOriginAttribute = includeCrossOriginAttribute ? 'crossorigin="anonymous"' : ''
scriptTags.push(`<script type="${scriptType}" src="${filePath}" ${crossOriginAttribute}></script>`)
scriptTags.push(`<script type="${scriptType}" src="${urlPath}" ${crossOriginAttribute}></script>`)
}
}

Expand Down

0 comments on commit 981f4fc

Please sign in to comment.