Compare commits

...

1 commit

Author SHA1 Message Date
Yarmo Mackenbach
d76cee1b2b
Add network module, flaresolverr options 2022-12-01 09:21:51 +01:00
3 changed files with 65 additions and 3 deletions

View file

@ -49,6 +49,10 @@ const opts = {
hostname: null,
policy: E.ProxyPolicy.NEVER
},
flaresolverr: {
url: '',
maxTimeout: 60000
},
claims: {
activitypub: {
url: null,

View file

@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const axios = require('axios')
const network = require('../network')
const validator = require('validator')
const jsEnv = require('browser-or-node')
@ -80,10 +80,10 @@ module.exports.fn = async (data, opts) => {
headers.signature = `keyId="${opts.claims.activitypub.url}#main-key",headers="(request-target) host date",signature="${signatureSig}",algorithm="rsa-sha256"`
}
axios.get(data.url,
network.get(data.url,
{
headers
})
}, opts)
.then(res => {
return res.data
})

58
src/network.js Normal file
View file

@ -0,0 +1,58 @@
/*
Copyright 2022 Yarmo Mackenbach
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const axios = require('axios')
/**
* Network related functions
* @module keys
*/
/**
* Make a GET HTTP request
* @function
* @param {string} url - URL for the Axios request
* @param {object} requestConfig - Config for Axios request
* @param {object} opts - doip options
* @returns {object}
*/
const get = (url, requestConfig, opts) => {
return new Promise((resolve, reject) => {
switch (opts.flaresolverr.url === '') {
case false:
axios.get(url, requestConfig)
.then(res => {
resolve(res)
})
.catch(err => {
reject(err)
})
break
case true:
default:
axios.get(url, requestConfig)
.then(res => {
resolve(res)
})
.catch(err => {
reject(err)
})
break
}
})
}
exports.get = get