-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex_3.js
36 lines (27 loc) · 848 Bytes
/
index_3.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
const express = require('express');
const app = express();
const UNSAFE_KEYS = ["__proto__", "constructor", "prototype"];
const merge = (obj1, obj2) => {
for (let key of Object.keys(obj2)) {
if (UNSAFE_KEYS.includes(key)) continue;
const val = obj2[key];
key = key.trim();
if (typeof obj1[key] !== "undefined" && typeof val === "object") {
obj1[key] = merge(obj1[key], val);
} else {
obj1[key] = val;
}
}
return obj1;
};
const defaults = {};
app.get("/", (req, res) => {
// Get q parameter
const query = req.query.query ?? "{}";
const queryObject = JSON.parse(query);
const options = {};
merge(options, defaults);
merge(options, queryObject);
res.setHeader("content-type", "text/plain; charset=utf-8");
process.exit();
});