Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async (ctx, next) => {
try {
if (ctx.path !== "/") {
// If we're in production, try /public first
return await koaSend(ctx, ctx.path, {
immutable,
root
});
}
} catch (e) {
/* Error? Go to next middleware... */
}
return next();
};
}
this.app.use(async ctx => {
if (ctx.status === 404) {
await KoaSend(ctx, this.config.spaFileRelativePath as string).catch(
err =>
console.error(`Error sending the specified SPA file: ${err}`)
)
}
})
}
const root = ctx =>
send(ctx, /\/$/.test(ctx.path) ? ctx.path + 'index.html' : ctx.path, {
root: config.destination
})
app.use(async (ctx) => {
await koaSend(ctx, 'index.html', { root: clientDistDirectory });
})
} else {
protected async sendFile () {
const { location, options = {} } = this.meta;
const { dir, base } = path.parse(location);
if (options.root) {
return await send(this.ctx, location, options);
}
await send(this.ctx, base, Object.assign({ root: dir }, options));
}
async (ctx) => koaSend(ctx, ctx.path, { gzip: true, root: options.appLocation }),
);
return function* staticRoute() {
this.assert(this.params.path, 404);
for (const root of roots) {
yield send(this, this.params.path, { root });
if (this.status === 200) {
application.log.debug(`Matched ${this.params.path} on ${root}`);
break;
} else {
application.log.debug(`No match for ${this.params.path} on ${root}`);
}
}
};
}
app.use(Route.get('/:user', function * show (username) {
let source
yield badge.show(username).then(user => {
this.set('ETag', crypto.createHash('md5').update(JSON.stringify(user)).digest('hex'))
this.set('Cache-Control', 'private')
source = user.badge
})
yield Send(this, source, {
root: '/'
})
}))
router.get('/dist/:path+', async ctx => {
await send(ctx, path.join('dist', ctx.params.path));
});
router.get('/favicon.ico', async ctx => {
await send(ctx, 'favicon.ico');
});