-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
58 lines (50 loc) · 1.59 KB
/
server.js
File metadata and controls
58 lines (50 loc) · 1.59 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const express = require('express');
const fetch = require('node-fetch');
const app = express();
app.use(express.json());
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
const YOUR_API_KEY = "2Thu70XL4YNc3gMmiPjr";
app.post('/generate', async (req, res) => {
try {
const body = {
apikey: YOUR_API_KEY,
data: req.body.url,
qrtype: 'static',
title: req.body.title,
transparent: req.body.transparent,
backcolor: req.body.backcolor,
frontcolor: req.body.frontcolor,
marker_out_color: req.body.marker_out_color,
marker_in_color: req.body.marker_in_color,
pattern: req.body.pattern,
marker: req.body.marker,
marker_in: req.body.marker_in
};
const qrRes = await fetch('https://api.qr.io/v1/create', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
});
const qrData = await qrRes.json();
res.json(qrData);
} catch (err) {
console.error("Error generating QR code:", err);
res.status(500).send("QR generation failed.");
}
});
app.post('/fetch-svg', async (req, res) => {
try {
const svgRes = await fetch(req.body.url);
const svgText = await svgRes.text();
res.send(svgText);
} catch (err) {
console.error("Error fetching SVG:", err);
res.status(500).send("Failed to fetch SVG.");
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));