Using Alpine variant for Docker

This commit is contained in:
Pablo Ferreiro
2022-06-28 20:35:11 +02:00
parent eaa76f0dd9
commit dd6a72eace
9 changed files with 91 additions and 78 deletions

View File

@@ -1,17 +1,16 @@
const Signer = require("../src/Signer")
const http = require("http")
const Signer = require("../src/Signer");
const http = require("http");
const PORT = process.env.PORT || 8080
const PORT = process.env.PORT || 8080;
const signer = new Signer()
const signer = new Signer();
const server = http.createServer(async (req, res) => {
res.writeHead(200, {
"Content-Type": "application/json",
"Cache-Control": "s-max-age=1, stale-while-revalidate" // caching stuff for vercel
});
if (req.method === "POST") {
res.writeHead(200, {
"Content-Type": "application/json",
"Cache-Control": "s-max-age=1, stale-while-revalidate" // caching stuff for vercel
});
// Get url from POST body
const buffers = [];
for await (const chunk of req) {
@@ -19,19 +18,28 @@ const server = http.createServer(async (req, res) => {
}
const url = Buffer.concat(buffers).toString();
const data = signer.sign(url)
console.log("Sent data from request with url: " + url)
res.write(JSON.stringify({
status: "ok",
data: {
...data,
navigator: signer.navigator()
}
}));
const data = signer.sign(url);
console.log("Sent data from request with url: " + url);
res.write(
JSON.stringify({
status: "ok",
data: {
...data,
navigator: signer.navigator()
}
})
);
} else {
res.write(
JSON.stringify({
status: "error",
data: "You have to send a POST request with a valid TikTok URL on the body!"
})
)
}
res.end()
})
res.end();
});
server.listen(PORT, () => {
console.log(`App listening on port: ${PORT}`);
})
});