0
SQL Serverへの接続にangular2とmssql
を使用しています。Mssqlノード、要求する入力値
これは私がこのrequest.body.usernameとパスワードに値を挿入することができますどのように私のコード
var express = require('express');
var app = express();
var sql = require("mssql");
// config for your database
var config = {
user: 'sa',
password: 'EnakAja123',
server: '192.168.1.37',
database: 'Angular'
};
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', false);
next();
});
app.post('/user', function (req, res) {
// connect to your database
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.input('username', req.body.username) <<
request.input('password', req.body.password) <<
request.query('select * from Angular_user where username = @username and password = @password', function (err, recordset) {
if (err) console.log(err)
// send records as a response
res.send(recordset);
});
});
});
var server = app.listen(5000, function() {
console.log('Server is running..');
});
のですか?この要求と応答が