From 03cf48324a60045824d3edc027c8b1b2b50eefcf Mon Sep 17 00:00:00 2001 From: Kevin Miller Date: Thu, 30 Apr 2020 08:32:03 -0400 Subject: [PATCH] chore: Remove all API redirects --- functions/api-proxy.js | 32 -------------------------------- gatsby-node.js | 24 ------------------------ netlify.toml | 1 - static/_redirects | 21 +-------------------- 4 files changed, 1 insertion(+), 77 deletions(-) delete mode 100644 functions/api-proxy.js diff --git a/functions/api-proxy.js b/functions/api-proxy.js deleted file mode 100644 index 86511cffb..000000000 --- a/functions/api-proxy.js +++ /dev/null @@ -1,32 +0,0 @@ -const fetch = require('node-fetch') - -exports.handler = function(event, context, callback) { - const { path, queryStringParameters } = event - let apiPath = path.replace('/api/', '') - if (queryStringParameters) { - apiPath += `?${Object.keys(queryStringParameters) - .map(key => key + '=' + queryStringParameters[key]) - .join('&')}` - } - - console.log( - `${apiPath}, ${event.headers.origin}, ${event.headers['x-forwarded-for']}`, - ) - - fetch(`https://covid.cape.io/${apiPath}`) - .then(response => { - return response.text() - }) - .then(data => { - callback(null, { - headers: { - 'X-Covid-Tracking-Proxy': 'yes', - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Headers': - 'Origin, X-Requested-With, Content-Type, Accept', - }, - statusCode: 200, - body: data, - }) - }) -} diff --git a/gatsby-node.js b/gatsby-node.js index dfc7879c5..1dcccac0c 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -67,18 +67,6 @@ exports.createPages = async ({ graphql, actions }) => { component: path.resolve(`./src/templates/state.js`), context: node, }) - - createRedirect({ - fromPath: `/api/states state=${node.state}`, - toPath: `/api/v1/states/${node.state.toLowerCase()}/current.json`, - isPermanent: true, - }) - - createRedirect({ - fromPath: `/api/states/daily.csv state=${node.state}`, - toPath: `/api/v1/states/${node.state.toLowerCase()}/current.csv`, - isPermanent: true, - }) }) result.data.allContentfulBlogPost.edges.forEach(({ node }) => { @@ -88,18 +76,6 @@ exports.createPages = async ({ graphql, actions }) => { context: node, }) }) - - createRedirect({ - fromPath: `/api/states* `, - toPath: `/.netlify/functions/api-proxy/states:splat`, - isPermanent: true, - }) - - createRedirect({ - fromPath: `/api/us* `, - toPath: `/.netlify/functions/api-proxy/us:splat`, - isPermanent: true, - }) } exports.onCreateWebpackConfig = ({ stage, actions, getConfig }) => { diff --git a/netlify.toml b/netlify.toml index 3ec16e76e..761e8bcda 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,7 +1,6 @@ [build] publish = "public" command = "npm run build" - functions = "functions" [context.production] command = "npm run build" diff --git a/static/_redirects b/static/_redirects index 4477c2eef..a2bfb2946 100644 --- a/static/_redirects +++ b/static/_redirects @@ -1,25 +1,6 @@ /api/v1/us.json /api/v1/us/current.json /api/v1/states.json /api/v1/states/current.json -/api/states.csv /api/v1/states/current.csv -/api/states/current.json /api/v1/states/current.json -/api/urls /api/v1/urls.json -/api/urls.csv /api/v1/urls.csv -/api/urls.html /api/v1/urls.html -/api/screenshots /api/v1/screenshots.json -/api/screenshots.csv /api/v1/screenshots.csv -/api/screenshots.html /api/v1/screenshots.html -/api/press /api/v1/press.json -/api/press.csv /api/v1/press.csv -/api/press.html /api/v1/press.html -/api/counties /api/v1/counties.json -/api/counties.csv /api/v1/counties.csv -/api/counties.html /api/v1/counties.html -/api/us.csv /api/v1/us/current.csv -/api/us/daily /api/v1/us/daily.json -/api/us/daily.csv /api/v1/us/daily.csv -/api/v1/states /api/v1/states/current.json - -/api/graphql /404 +/api/* https://covid.cape.io/:splat 200 /charts/dash http://35.212.27.3:8050/ /graphql /api/graphql