Commit 611bc9bb by Пронин Евгений

лобавлен запрос getData и cors

1 parent 2cb06e9a
// подключение express
const express = require("express");
// создаем объект приложения
const cors = require('cors')
const app = express();
// определяем обработчик для маршрута "/"
......@@ -44,7 +45,7 @@ function makeDevice(cards) {
}
}
app.get("/getRfid", (req, res) => {
app.get("/getRfid", cors(), (req, res) => {
var msg = JSON.stringify(state, null, '\t');
if (req.query.callback !== undefined) {
msg = req.query.callback + "(" + msg + ");";
......@@ -54,6 +55,22 @@ app.get("/getRfid", (req, res) => {
});
app.get("/getData", (req, res) => {
let terminal_sn = state.terminal_sn;
let data = {
"pult_sn" : terminal_sn,
"serv_ip" : "unknown",
"serv_port" : "unknown"
};
var msg = JSON.stringify(data, null, '\t');
if (req.query.callback !== undefined) {
msg = req.query.callback + "(" + msg + ");";
return res.type('application/javascript').send(msg);
}
res.type('application/json').send(msg);
});
// положить карту
app.get("/", (req, res) => {
res.status(200).send(`<ul>
......
......@@ -232,6 +232,15 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
"cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"requires": {
"object-assign": "^4",
"vary": "^1"
}
},
"create-error-class": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/create-error-class/-/create-error-class-3.0.2.tgz",
......@@ -774,6 +783,11 @@
"path-key": "^2.0.0"
}
},
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
......
......@@ -7,6 +7,7 @@
"dev": "nodemon ./app"
},
"dependencies": {
"cors": "^2.8.5",
"express": "~4.16.4"
},
"devDependencies": {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!