How to use koa-send - 10 common examples

To help you get started, we’ve selected a few koa-send examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github leebenson / reactql / src / runner / app.ts View on Github external
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();
  };
}
github kaleabmelkie / meseret / src / server / server-app.ts View on Github external
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}`)
            )
          }
        })
      }
github Symbitic / markbook / src / backends / server.js View on Github external
const root = ctx =>
    send(ctx, /\/$/.test(ctx.path) ? ctx.path + 'index.html' : ctx.path, {
      root: config.destination
    })
github darkwire / darkwire-server / src / index.js View on Github external
app.use(async (ctx) => {
    await koaSend(ctx, 'index.html', { root: clientDistDirectory });
  })
} else {
github SpoonX / stix / src / Library / Response / Response.ts View on Github external
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));
  }
github storyforj / fervor / src / server / static.js View on Github external
    async (ctx) => koaSend(ctx, ctx.path, { gzip: true, root: options.appLocation }),
  );
github patternplate / patternplate / packages / boilerplate-server / source / application / routes / static.js View on Github external
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}`);
      }
    }
  };
}
github hiendv / hireable / src / index.js View on Github external
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: '/'
  })
}))
github expo / snack-web / server / src / routes.js View on Github external
router.get('/dist/:path+', async ctx => {
    await send(ctx, path.join('dist', ctx.params.path));
  });
github expo / snack-web / src / server / routes.js View on Github external
router.get('/favicon.ico', async ctx => {
    await send(ctx, 'favicon.ico');
  });

koa-send

Transfer static files

MIT
Latest version published 4 years ago

Package Health Score

79 / 100
Full package analysis

Popular koa-send functions