From d42d43e90fb13d3af5d9cb1dd4c7562a14649865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Tue, 2 Apr 2019 05:00:45 -0700 Subject: [PATCH] use tinyURL Summary: As of today, Google URL shortener is retired. Moving to tinyURL instead. However, tinyURL doesn't support CORS headers, therefore additionally adding a CORS proxy. Reviewed By: davidaurelio Differential Revision: D14722636 fbshipit-source-id: 2ec41bb43287102543f1ac31bb76df57d71ba134 --- .../src/components/Playground/URLShortener.js | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/website/src/components/Playground/URLShortener.js b/website/src/components/Playground/URLShortener.js index 4dc99190..77130a0f 100644 --- a/website/src/components/Playground/URLShortener.js +++ b/website/src/components/Playground/URLShortener.js @@ -12,8 +12,6 @@ import React, {Component} from 'react'; import {Tooltip, notification, Button, Input} from 'antd'; import './URLShortener.css'; -const API_KEY = 'AIzaSyCRvdtNY07SGUokChS8oA9EaYJafFL0zMI'; - type State = { shortURL: ?string, loading: boolean, @@ -53,19 +51,13 @@ export default class URLShortener extends Component<{}, State> { }); } - fetch(`https://www.googleapis.com/urlshortener/v1/url?key=${API_KEY}`, { - method: 'POST', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - kind: 'urlshortener#url', - longUrl: window.location.href, - }), - }) - .then(res => res.json()) - .then(({id}) => this.setState({shortURL: id, loading: false})) + fetch( + `https://cors-anywhere.herokuapp.com/tinyurl.com/api-create.php?url=${ + window.location.href + }`, + ) + .then(res => res.text()) + .then(shortURL => this.setState({shortURL, loading: false})) .catch(() => this.setState({shortURL: null, loading: false})); }, );