Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

terraria-latest-version-api

node v10.24.1
version: 1.0.2
endpointsharetweet
const url = require('url') const { send } = require('micro') const axios = require('axios') const xpath = require('xpath-html'); const terrariaUrl = 'https://terraria.org' const selector = "//*[text() = 'PC Dedicated Server']" exports.endpoint = async function (req, res) { try { const redirect = new URL(req.url, 'https://localhost/').searchParams.get('dl') const html = await axios(terrariaUrl).then(res => res.data) const node = xpath.fromPageSource(html).findElement(selector); const dlUrl = terrariaUrl + node.getAttribute('href') if (redirect == '1') { res.setHeader('Location', dlUrl) send(res, 307) } else { send(res, 200, dlUrl) } } catch (e) { console.log(e) send(res, 500, 'Internal Server Error') } }
Loading…

no comments

    sign in to comment