Skip to content
Permalink
Browse files

Enable function usage summary

  • Loading branch information...
marcomontalbano committed Sep 17, 2019
1 parent e9b6c01 commit 729c9dd2de0d1131e07b2a157c0ccf55ae96daf2
Showing with 32 additions and 16 deletions.
  1. +2 −0 .gitignore
  2. +14 −0 bin/build-db
  3. +1 −1 netlify.toml
  4. +8 −10 src/index.js
  5. +6 −4 src/lambda/classes/proxiedFetch.js
  6. +1 −1 src/lambda/netlify.js
@@ -8,3 +8,5 @@ yarn-error.log

/.cache
/dist

/src/db.json
@@ -0,0 +1,14 @@
#!/usr/bin/env node

require('dotenv').config();

const fs = require('fs');

const netlify = require('../src/lambda/netlify');
const dbPath = `${__dirname}/../src/db.json`;

fs.writeFileSync(dbPath, '{}');
netlify.handler({}, {}, (error, content) => {
const netlify = JSON.parse(content.body);
fs.writeFileSync(dbPath, JSON.stringify({ netlify }, undefined, 2));
});
@@ -1,5 +1,5 @@
[build]
command = "npm run build"
command = "./bin/build-db && npm run build"
publish = "dist/client"
functions = "dist/server"

@@ -6,7 +6,7 @@ import imageNotFound from './images/not-found.jpg';
import imageLoading from './images/loading.jpg';

const lambdaUrl = `${location.protocol}//${location.host}/.netlify/functions`;
const enableFunctionUsageSummary = false;
const enableFunctionUsageSummary = true;

const videoIcons = {
dailymotion: require('./images/providers/dailymotion.png'),
@@ -74,15 +74,13 @@ function updateQuota(data, functionType) {
}

if (enableFunctionUsageSummary) {
fetch(`${lambdaUrl}/netlify`)
.then(response => response.json())
.then(data => {
if (data.error !== true) {
updateQuota(data, 'invocations');
updateQuota(data, 'runtime');
document.querySelector('.functions').classList.remove('hidden');
}
});
const { netlify } = require('./db.json');

if (netlify) {
updateQuota(netlify, 'invocations');
updateQuota(netlify, 'runtime');
document.querySelector('.functions').classList.remove('hidden');
}
}

document.querySelectorAll('a').forEach(function (a) {
@@ -1,13 +1,15 @@
import nodeFetch from 'node-fetch';
import HttpsProxyAgent from 'https-proxy-agent';
const nodeFetch = require('node-fetch').default;
const HttpsProxyAgent = require('https-proxy-agent');

const { HTTP_PROXY, HTTPS_PROXY } = process.env;

export default (url, options = {}) => {
const fetch = (url, options = {}) => {

if (HTTP_PROXY) {
options.agent = new HttpsProxyAgent(HTTP_PROXY);
}

return nodeFetch(url, options);
}
};

module.exports = fetch;
@@ -1,4 +1,4 @@
import fetch from './classes/proxiedFetch';
const fetch = require('./classes/proxiedFetch');

const { SITE_ID, NETLIFY_ACCESS_TOKEN } = process.env;

0 comments on commit 729c9dd

Please sign in to comment.
You can’t perform that action at this time.