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
This commit is contained in:
committed by
Facebook Github Bot
parent
bfc6319daa
commit
d42d43e90f
@@ -12,8 +12,6 @@ import React, {Component} from 'react';
|
|||||||
import {Tooltip, notification, Button, Input} from 'antd';
|
import {Tooltip, notification, Button, Input} from 'antd';
|
||||||
import './URLShortener.css';
|
import './URLShortener.css';
|
||||||
|
|
||||||
const API_KEY = 'AIzaSyCRvdtNY07SGUokChS8oA9EaYJafFL0zMI';
|
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
shortURL: ?string,
|
shortURL: ?string,
|
||||||
loading: boolean,
|
loading: boolean,
|
||||||
@@ -53,19 +51,13 @@ export default class URLShortener extends Component<{}, State> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(`https://www.googleapis.com/urlshortener/v1/url?key=${API_KEY}`, {
|
fetch(
|
||||||
method: 'POST',
|
`https://cors-anywhere.herokuapp.com/tinyurl.com/api-create.php?url=${
|
||||||
headers: {
|
window.location.href
|
||||||
Accept: 'application/json',
|
}`,
|
||||||
'Content-Type': 'application/json',
|
)
|
||||||
},
|
.then(res => res.text())
|
||||||
body: JSON.stringify({
|
.then(shortURL => this.setState({shortURL, loading: false}))
|
||||||
kind: 'urlshortener#url',
|
|
||||||
longUrl: window.location.href,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(({id}) => this.setState({shortURL: id, loading: false}))
|
|
||||||
.catch(() => this.setState({shortURL: null, loading: false}));
|
.catch(() => this.setState({shortURL: null, loading: false}));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user