Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async execute(invocation: Readonly): Promise {
if(this.option.rootPath && !this.option.rootPath.startsWith("/"))
this.option.rootPath = "/" + this.option.rootPath
const rootPath = this.option.rootPath || ""
//no route = no controller = possibly static file request
if (!invocation.ctx.route && invocation.ctx.path.toLowerCase().startsWith(rootPath.toLowerCase())) {
//check if not in root path then proceed
//execute action result directly here, so if file not found it will possible to chain with next middleware
try {
const path = invocation.ctx.path.substr(rootPath.length)
const result = new FileActionResult(path, this.option)
await result.execute(invocation.ctx)
return ActionResult.fromContext(invocation.ctx)
}
catch (e) {
if (e.status && e.status === 404)
return invocation.proceed()
else
throw e
}
}
else
return invocation.proceed()
}
}