-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// grab the packages we need
const request = require("request").defaults({ encoding: null });
var express = require("express");
const resizeImg = require("resize-image-buffer");
var app = express();
var port = process.env.PORT || 5000;
// routes will go here
app.get("/", async function (req, res) {
res.send("<h1>ISIZER</h1>");
});
app.get("/api/resize", async function (req, res) {
const { wd, ht, url } = req.query;
await request.get(url, async (error, response, body) => {
console.log(response);
if (response.statusCode) {
}
if (!error && response.statusCode == 200) {
const image = await resizeImg(Buffer.from(body), {
width: Number(wd),
height: Number(ht),
});
res.contentType(response.headers["content-type"]);
return res.end(image);
}
return res.status(406).json({
message: "Only content of type image(bmp, jpg, png) is accepted",
});
});
});
// start the server
app.listen(port, () => {
console.log("Server started! at port", port);
});