tsapi3/server.js
2024-11-25 12:51:41 -05:00

66 lines
1.7 KiB
JavaScript
Executable File

/**
* Module Dependencies
*/
const config = require('./config'),
restify = require('restify'),
mysql = require('mysql')
/**
* Initialize Server
*/
const server = restify.createServer({
name : config.name,
version : config.version,
url : config.hostname
});
var connection = config.db.get;
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());
/*server.get('/echo/:name', function (req, res, next) {
res.send(req.params);
return next();
});*/
//rest api to get all results
server.get('/api/today', function (req, res) {
//connection.query('select * from tracking limit 10', function (error, results, fields) {
connection.query('CALL CP_RPT_TodaysCounts();', function (error, results, fields) {
if (error) throw error;
res.end(JSON.stringify(results));
//console.log(results);
//res.end();
});
});
server.get('/api/campaign',function(req, res){
connection.query('CALL CP_RPT_TweetsByScreenName ();',function(error, results, fields){
if(error) throw error;
//https://www.sitepoint.com/using-node-mysql-javascript-client/
res.end(JSON.stringify(results));
//res.end(results);
});
});
/*
server.get('',function(){
connection.query('',function(){});
});
*/
//rest api to get a single employee data
//rest api to create a new record into mysql database
//rest api to update record into mysql database
//rest api to delete record from mysql database
server.get('/', function(req, res){
console.log('Welcome Nodejs restify');
});
server.listen(3001, function () {
console.log('%s listening at %s', server.name, server.url);
});