Try implementing backend with Node's http
This commit is contained in:
parent
699f93fdbc
commit
e23e590251
1 changed files with 19 additions and 16 deletions
35
api/toot.js
35
api/toot.js
|
@ -16,20 +16,23 @@
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function (req, res) {
|
const http = require("http");
|
||||||
let text = "";
|
|
||||||
let instanceURL = "https://mastodon.social/";
|
|
||||||
if (req.body) {
|
|
||||||
if (req.body.text) {
|
|
||||||
text = req.body.text;
|
|
||||||
}
|
|
||||||
if (req.body.instance) {
|
|
||||||
instanceURL = req.body.instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.redirect(
|
http
|
||||||
303,
|
.createServer(async (req, res) => {
|
||||||
instanceURL + "share?text=" + encodeURIComponent(text)
|
const buffers = [];
|
||||||
);
|
for await (const chunk of req) {
|
||||||
};
|
buffers.push(chunk);
|
||||||
|
}
|
||||||
|
const data = Buffer.concat(buffers).toString();
|
||||||
|
const params = new URLSearchParams(data);
|
||||||
|
|
||||||
|
const text = params.get("text") || "";
|
||||||
|
const instanceURL = params.get("instance") || "https://mastodon.social/";
|
||||||
|
|
||||||
|
const finalURL = new URL("share", instanceURL);
|
||||||
|
finalURL.search = new URLSearchParams({ text }).toString();
|
||||||
|
|
||||||
|
res.writeHead(303, { Location: finalURL.toString() }).end();
|
||||||
|
})
|
||||||
|
.listen(8000);
|
||||||
|
|
Reference in a new issue