Я установил конечную точку косой черты.
Я хочу сделать так, чтобы пользователь вводил: http / website.com / date = 2019-08-01 & station = 41027 & daysForward = 5
, чтобы иметь возможность изменять три параметра для получения разных данных.
date = "первый параметр"
station = "второй параметр"
daysForward = "третий параметр"
var express = require("express")
var app = express()
var mysql = require('mysql')
// Server port
var HTTP_PORT = 8000;
// Start server
app.listen(HTTP_PORT, () => {
console.log("Server running on port %PORT%".replace("%PORT%",HTTP_PORT))
});
var con = mysql.createConnection({
host: "192.168.0.1",
port: "3333",
user: "username",
password: "pass"
});
con.connect(function(err) {
if (err) throw err;
});
let selectCustomers = function (query, cb) {
let aladinModel = '';
if (query.date && query.station && query.daysForward) {
con.query(`CALL aladin_surfex.Get_mod_cell_values_meteogram(${query.date},${query.station},${query.daysForward})`, function (err, result, fields) {
if (err) throw err;
console.log(result);
aladinModel = result;
return cb(aladinModel);
});
}
else return cb(aladinModel);
};
// Root endpoint
app.get("/", (req, res, next) => {
selectCustomers (req. запрос, функция (aladinModel) {res.json ({aladinModel}) *
const date = req.query.date;
const station = req.query.station;
const daysForward = req.query.daysForward;
const query = `CALL aladin_surfex.Get_mod_cell_values_meteogram(${date}, ${station}, ${daysForward})`;
con.query(query, function (err, result, fields) {
if (err) throw err;
aladinModel = result;
});
res.json({aladinModel})
});
app.use(function(req, res){
res.status(404);
});
Я получил эту ошибку:
ReferenceError: aladinModel is not defined
at app.get (C:\Users\Admin\node-express\server.js:54:13)
at Layer.handle [as handle_request] (C:\Users\Admin\node-express\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Admin\node-express\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\Admin\node-express\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\Admin\node-express\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\Admin\node-express\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\Admin\node-express\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\Admin\node-express\node_modules\express\lib\router\index.js:275:10)
at expressInit (C:\Users\Admin\node-express\node_modules\express\lib\middleware\init.js:40:5)
at Layer.handle [as handle_request] (C:\Users\Admin\node-express\node_modules\express\lib\router\layer.js:95:5)