Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs #69 Add support proxy connection for REST endpoint #70

Merged
merged 2 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions example/typescript/proxy_instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Mastodon, { Instance, ProxyConfig } from 'megalodon'

declare var process: {
env: {
PROXY_HOST: string
PROXY_PORT: number
PROXY_PROTOCOL: string
}
}

const BASE_URL: string = 'http://mastodon.social'

const proxy: ProxyConfig = {
host: process.env.PROXY_HOST,
port: process.env.PROXY_PORT,
protocol: process.env.PROXY_PROTOCOL
}

Mastodon.get<Instance>('/api/v1/instance', {}, BASE_URL, proxy).then(res => {
console.log(res)
})
26 changes: 26 additions & 0 deletions example/typescript/proxy_timeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Mastodon, { Status, Response, ProxyConfig } from 'megalodon'

declare var process: {
env: {
MASTODON_ACCESS_TOKEN: string
PROXY_HOST: string
PROXY_PORT: number
PROXY_PROTOCOL: string
}
}

const BASE_URL: string = 'https://mastodon.social'

const access_token: string = process.env.MASTODON_ACCESS_TOKEN

const proxy: ProxyConfig = {
host: process.env.PROXY_HOST,
port: process.env.PROXY_PORT,
protocol: process.env.PROXY_PROTOCOL
}

const client = new Mastodon(access_token, BASE_URL + '/api/v1', 'megalodon', proxy)

client.get<Array<Status>>('/timelines/public').then((resp: Response<Array<Status>>) => {
console.log(resp.data)
})
2 changes: 1 addition & 1 deletion example/typescript/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ const access_token: string = process.env.MASTODON_ACCESS_TOKEN

const client = new Mastodon(access_token, BASE_URL + '/api/v1')

client.get<Array<Status>>('/timelines/home').then((resp: Response<Array<Status>>) => {
client.get<Array<Status>>('/timelines/public').then((resp: Response<Array<Status>>) => {
console.log(resp.data)
})
35 changes: 35 additions & 0 deletions example/typescript/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
dependencies:
"@types/node" "*"

agent-base@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee"
integrity sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==
dependencies:
es6-promisify "^5.0.0"

ajv@^5.3.0:
version "5.5.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965"
Expand Down Expand Up @@ -153,6 +160,13 @@ debug@=3.1.0:
dependencies:
ms "2.0.0"

debug@^3.1.0:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
dependencies:
ms "^2.1.1"

debug@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
Expand All @@ -173,6 +187,18 @@ ecc-jsbn@~0.1.1:
jsbn "~0.1.0"
safer-buffer "^2.1.0"

es6-promise@^4.0.3:
version "4.2.8"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a"
integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==

es6-promisify@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203"
integrity sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=
dependencies:
es6-promise "^4.0.3"

extend@~3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa"
Expand Down Expand Up @@ -267,6 +293,14 @@ http-signature@~1.2.0:
jsprim "^1.2.2"
sshpk "^1.7.0"

https-proxy-agent@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-3.0.0.tgz#0106efa5d63d6d6f3ab87c999fa4877a3fd1ff97"
integrity sha512-y4jAxNEihqvBI5F3SaO2rtsjIOnnNA8sEbuiP+UhJZJHeM2NRm6c09ax2tgqme+SgUUvjao2fJXF4h3D6Cb2HQ==
dependencies:
agent-base "^4.3.0"
debug "^3.1.0"

is-buffer@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725"
Expand Down Expand Up @@ -337,6 +371,7 @@ log4js@^5.2.2:
"@types/request" "^2.47.0"
"@types/ws" "^6.0.1"
axios "^0.18.1"
https-proxy-agent "^3.0.0"
moment "^2.24.0"
oauth "^0.9.15"
request "^2.87.0"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@types/request": "^2.47.0",
"@types/ws": "^6.0.1",
"axios": "^0.18.1",
"https-proxy-agent": "^3.0.0",
"moment": "^2.24.0",
"oauth": "^0.9.15",
"request": "^2.87.0",
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Mastodon, { MegalodonInstance } from './mastodon'
import Mastodon, { MegalodonInstance, ProxyConfig } from './mastodon'
import StreamListener from './stream_listener'
import WebSocket from './web_socket'
import Response from './response'
Expand Down Expand Up @@ -43,6 +43,7 @@ export {
MegalodonInstance,
RequestCanceledError,
isCancel,
ProxyConfig,
/**
* Entities
*/
Expand Down
Loading