How to use altair-static - 7 common examples

To help you get started, we’ve selected a few altair-static 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 imolorhe / altair / packages / altair-electron / src / window.js View on Github external
fs.readFile(filePath, 'utf8', function(err, data) {
        if (err) {
          return console.log('Error loading file to buffer.', err);
        }
        if (filePath && filePath.includes('index.html')) {
          data = renderAltair();
        }

        // Load the data from the file into a buffer and pass it to the callback
        // Using the mime package to get the mime type for the file, based on the file name
        callback({ mimeType: mime.lookup(filePath), data: Buffer.from(data) });
      });
    });
github imolorhe / altair / packages / altair-express-middleware / index.ts View on Github external
export const altairExpress = (opts: RenderOptions): express.Express => {
  const app = express();
  app.disable('strict routing');

  app.get('/', (req, res) => {
    if (req.originalUrl.substr(-1) !== '/') {
      // We need the trailing slash to enable relative file paths to work
      return res.redirect(301, req.originalUrl + '/');
    }
    return res.send(renderAltair(opts));
  });
  app.get('/initial_options.js', (req, res) => {
    res.set('Content-Type', 'text/javascript');
    return res.send(renderInitialOptions(opts));
  });
  app.use(express.static(getDistDirectory()));

  /**
   * Catch-all route
   */
  app.get('*', (req, res) => {
    return res.send('404.');
  });

  return app;
};
github imolorhe / altair / packages / altair-express-middleware / index.ts View on Github external
app.get('/', (req, res) => {
    if (req.originalUrl.substr(-1) !== '/') {
      // We need the trailing slash to enable relative file paths to work
      return res.redirect(301, req.originalUrl + '/');
    }
    return res.send(renderAltair(opts));
  });
  app.get('/initial_options.js', (req, res) => {
github imolorhe / altair / packages / altair-electron / src / window.js View on Github external
protocol.registerBufferProtocol('altair', (request, callback) => {

    const requestDirectory = getDistDirectory();
    const filePath = path.join(requestDirectory, new url.URL(request.url).pathname);
    const indexPath = path.join(requestDirectory, 'index.html');

    getFilePath(filePath).then((filePath) => {
      if (!filePath) {
        filePath = indexPath;
      }

      fs.readFile(filePath, 'utf8', function(err, data) {
        if (err) {
          return console.log('Error loading file to buffer.', err);
        }
        if (filePath && filePath.includes('index.html')) {
          data = renderAltair();
        }
github imolorhe / altair / packages / altair-koa-middleware / index.ts View on Github external
router.get(`${url}/:path+`, async ctx => {
    await send(ctx, ctx.params.path, { root: getDistDirectory() });
  })
};
github imolorhe / altair / packages / altair-koa-middleware / index.ts View on Github external
router.get(url, async (ctx, next) => {

    ctx.body = renderAltair({ baseURL: ctx.url.replace(/\/?$/, '/'), ...opts });

    await next();
  })
github imolorhe / altair / packages / altair-express-middleware / index.ts View on Github external
app.get('/initial_options.js', (req, res) => {
    res.set('Content-Type', 'text/javascript');
    return res.send(renderInitialOptions(opts));
  });
  app.use(express.static(getDistDirectory()));

altair-static

Static package for altair graphql client

MIT
Latest version published 22 days ago

Package Health Score

89 / 100
Full package analysis