Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Meteor.startup(function() {
// Purge cloudflare cache
if (!Meteor.settings.development) {
const cf = new Cloudflare({
email: Meteor.settings.cloudflare.email,
key: Meteor.settings.cloudflare.key
});
cf.zones
.purgeCache(Meteor.settings.cloudflare.zoneId, {
purge_everything: true
})
.catch(error => console.error(error));
}
//Loggly initialisation
Logger = new Loggly({
token: Meteor.settings.loggly.token,
subdomain: Meteor.settings.loggly.subdomain,
auth: {
import logger from './logger';
// Load config
const cfConfig = config.cloudflare || {};
// Check config
const isLiveServer = ['staging', 'production'].includes(config.env);
const hasConfig = Boolean(cfConfig.email && cfConfig.key && cfConfig.zone);
if (isLiveServer && !hasConfig) {
logger.warn('Cloudflare config is incomplete: it must includes an email, a key and a zone');
} else if (!isLiveServer && hasConfig) {
logger.info('A Cloudflare config was provided on a Live/Test environment. Some methods will be stubbed.');
}
const CloudflareLib = cloudflare({ email: cfConfig.email, key: cfConfig.key });
// Export some helpers
/**
* Purge the given page from cloudflare's cache. In dev environments this function
* will only log to the console and will skip the call to cloudflare.
*
* Don't include the trailing `/` in `pagePaths`, a second version of the URL with
* it is already generated automatically. We do that because Cloudflare consider
* `https://opencollective.com/babel` and `https://opencollective.com/babel/` as two
* different URLs.
*
* @param {string|array} pagePaths - a path or an array of paths `/eslint`, `['/', '/about']`
* @returns {Promise}
*/
export const purgeCacheForPage = pagePaths => {
const s3Client = s3.createClient({
maxAsyncS3: 20, // this is the default
s3RetryCount: 3, // this is the default
s3RetryDelay: 1000, // this is the default
multipartUploadThreshold: 20971520, // this is the default (20 MB)
multipartUploadSize: 15728640, // this is the default (15 MB)
s3Options: {
accessKeyId: process.env.S3_ACCESS_KEY,
secretAccessKey: process.env.S3_SECRET_KEY,
region: 'us-east-1',
},
});
const cloudfront = new aws.CloudFront({ apiVersion: '2017-03-25' });
const cf = cloudflare({
email: process.env.CLOUDFLARE_EMAIL,
key: process.env.CLOUDFLARE_API_KEY,
});
const uploadToS3Async = (localPath, s3Path) =>
new Promise((resolve, reject) => {
const params = {
localFile: localPath,
s3Params: {
Bucket: process.env.S3_BUCKET,
Key: s3Path,
},
};
const uploader = s3Client.uploadFile(params);
var ccf = (config.API.cloudflare.enable == "yes"
? require("cloudflare").createClient(config.API.cloudflare)
: null
);
var ncf = require("node_cloudflare");
var debug = require("debug")("bird3:cloudflare");
module.exports = function(app) {
// This is the local app instance, invoked before vhost.
debug("BIRD3 CloudFlare Worker: Starting...");
if(ccf!=null) {
debug("BIRD3 CloudFlare Worker: CF client enabled!");
}
ncf.load(function(error, fs_error){
if(error){
throw error;
import CFClient from 'cloudflare';
import dotenv from 'dotenv';
dotenv.config();
const cf = new CFClient({
email: process.env.CLOUDFLARE_EMAIL,
key: process.env.CLOUDFLARE_API_KEY,
});
async function purgeCDNCache() {
const zone = (await cf.browseZones({
name: process.env.CLOUDFLARE_DOMAIN,
})).result[0];
await cf.deleteCache(zone.id, {
purge_everything: true,
});
console.log('[postinstall] CDN zone %s flushed', zone.id);
}
purgeCDNCache();
cfcli.init = function (token, email) {
cfcli.cloudflare = require('cloudflare').createClient({
email: email,
token: token
});
};