const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser());
const PORT = process.env.PORT || 80;
app.listen(PORT, () => {
try {
console.log(`Server started on ${PORT}...`);
} catch (e) {
console.error(`${e} - app.listen`);
}
});
const userList = [];
let userData = [];
app.get("/userList", (req, res) => {
try {
res.send(userList);
} catch (e) {
console.error(`${e} - app.get("/userList")`);
}
});
app.get("/userData", (req, res) => {
try {
res.send(userData);
} catch (e) {
console.error(`${e} - app.get("/userData")`);
}
});
app.post("/userData", (req, res) => {
try {
userData = req.body;
} catch (e) {
console.error(`${e} - app.post("/userData")`);
}
});
app.post("/userList", (req, res) => {
try {
userList.push(req.body);
} catch (e) {
console.error(`${e} - app.post("/userList")`);
}
});
app.use(cors());