const express = require('express')
var { Readability } = require('@mozilla/readability');
var { JSDOM } = require('jsdom');
const request = require('request');
const e = require('express');
const { head } = require('request');
const DDG = require('duck-duck-scrape');
const app = express()
const port = 3001 //which port?
const noPortInDomain = true //is there a port visible in the domain?
const httpOrHttps = "https" //is set to http when changed to anything besides the default (http)
const subdomain = "server.sparksammy.com" //subdomain where your basednet instance resides.
var siteName;
// code below.
if (httpOrHttps == "https") {
if (noPortInDomain == false) {
siteName = `https://${subdomain}:${port}`
} else {
siteName = `https://${subdomain}`
}
} else {
if (noPortInDomain == false) {
siteName = `http://${subdomain}:${port}`
} else {
siteName = `http://${subdomain}`
}
}
const proxying = `${siteName}/net?url=`
var headHTML = `
BasedNet
`
app.get('/', (req, res) => {
res.send(`
${headHTML}
BasedNet
Check out the other project, BasedFind!
Copyright Samuel Lord. Licensed under the MIT license.
Source available on the BasedNet GitHub.
`)
})
app.get('/find', (req, res) => {
const search = DDG.search(req.query.q)
let thtml;
search.results.forEach(function(e,i) {
thtml = `${thtml}
$search.results[i].title}`
});
res.send(thtml);
})
app.get('/basedfind', (req, res) => {
let dp;
if (noPortInDomain == false) {
dp = port
} else {
dp = 80
}
res.send(`
${headHTML}
BasedFind *early build*
Back to BasedNet.
Copyright Samuel Lord. Licensed under the MIT license. Powered by DuckDuckGo Lite.
Source available on the BasedNet GitHub.
`)
})
app.get('/net', (req, res) => {
const reqf = req;
const resf = res;
var baseurl = ""
let dp;
if (noPortInDomain == false) {
dp = port
} else {
dp = 80
}
request(req.query.url, { json: false }, (err, res, body) => {
if (err) { return console.log(err); }
//console.log(body)
try {
if (req.query.url.startsWith("http://")) {
baseurl = req.query.url.replace("http://","")
} else {
baseurl = req.query.url.replace("https://","")
}
var arrOfURL = req.query.url.split("/")
var urlNoDoc = req.query.url
for (let i = 0; i < arrOfURL.length; i++) {
if (String(arrOfURL[i]).includes("html")) {
arrOfURL.pop(i)
urlNoDoc = arrOfURL.join("/")
break;
}
}
var arrOfURL2 = req.query.url.split("/")
const domain = arrOfURL2[2]
var olddom = new JSDOM(`${body}`, { url: req.query.url});
var newbody = body
var arrOfTags = []
newbody = newbody.replace(/
BasedNet
BasedFind *early build*
${liteRead.title}
${contentLatest}