http = require('http')
url = require('url')
mysql = require('mysql')
json = require('json')
server = http.createServer((req, res) ->
pathname = decodeURIComponent(url.parse(req.url).pathname)
sql = pathname.split('/')[1]
if sql == 'kill'
res.writeHead 200, 'Content-Type': 'text/html; charset=UTF-8'
res.end '
Server кирдык'
server.close ''
req.connection.destroy ''
console.log 'кирдык'
process.exit ''
return
connection = mysql.createConnection(
host: 'airs.ce5k6a6fvfk2.us-east-1.rds.amazonaws.com'
user: 'userairs'
password: 'userairs'
database: 'airs')
connection.connect()
if sql.length > 0
connection.query sql, (err, rows, fields) ->
connection.end()
if rows
console.log json.stringify(rows)
res.writeHead 200, 'Content-Type': 'text/tab-separated-values; charset=UTF-8'
if !rows
res.end 'Неверный sql-запрос!'
if rows
res.end json.stringify(rows)
return
else
res.writeHead 200, 'Content-Type': 'text/tab-separated-values; charset=UTF-8'
res.end 'Введите sql-запрос!'
return
)
server.listen 3000