Inital commit from RPi3
This commit is contained in:
commit
dbd3caba1e
67
.gitignore
vendored
Normal file
67
.gitignore
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
#Visual Studio Code Settings
|
||||
.vscode/
|
||||
|
||||
#Ignore Real Config Files a distributed one is included for structure.s
|
||||
config.js
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# next.js build output
|
||||
.next
|
19
config.js.dist
Executable file
19
config.js.dist
Executable file
@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
|
||||
var mysql = require('mysql');
|
||||
|
||||
module.exports = {
|
||||
name: 'TS-api3',
|
||||
hostname : 'http://localhost',
|
||||
version: '3.0.1',
|
||||
env: process.env.NODE_ENV || 'development',
|
||||
port: process.env.PORT || 3000,
|
||||
db: {
|
||||
get : mysql.createConnection({
|
||||
host : 'ip or host name here',
|
||||
user : 'yOuR_UsEr',
|
||||
password : 'S0mePa$$w0rd',
|
||||
database : 'YourDBs'
|
||||
})
|
||||
}
|
||||
}
|
14
dockerfile
Normal file
14
dockerfile
Normal file
@ -0,0 +1,14 @@
|
||||
FROM timpreble/alpinearm:3.5.3
|
||||
|
||||
#Create App Directory
|
||||
WORKDIR /usr/src/api
|
||||
|
||||
#Install Dependencies
|
||||
COPY package.json .
|
||||
RUN npm install
|
||||
|
||||
#Bundle ap source
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3001
|
||||
CMD ["npm", "start"]
|
76
main.js.backup
Normal file
76
main.js.backup
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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('/employees', 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));
|
||||
});
|
||||
});
|
||||
|
||||
//rest api to get a single employee data
|
||||
server.get('/employees/:id', function (req, res) {
|
||||
connection.query('select * from employee where id=?', [req.params.id], function (error, results, fields) {
|
||||
if (error) throw error;
|
||||
res.end(JSON.stringify(results));
|
||||
});
|
||||
});
|
||||
|
||||
//rest api to create a new record into mysql database
|
||||
server.post('/employees', function (req, res) {
|
||||
var postData = req.body;
|
||||
connection.query('INSERT INTO employee SET ?', postData, function (error, results, fields) {
|
||||
if (error) throw error;
|
||||
res.end(JSON.stringify(results));
|
||||
});
|
||||
});
|
||||
|
||||
//rest api to update record into mysql database
|
||||
server.put('/employees', function (req, res) {
|
||||
connection.query('UPDATE `employee` SET `employee_name`=?,`employee_salary`=?,`employee_age`=? where `id`=?', [req.body.employee_name,req.body.employee_salary, req.body.employee_age, req.body.id], function (error, results, fields) {
|
||||
if (error) throw error;
|
||||
res.end(JSON.stringify(results));
|
||||
});
|
||||
});
|
||||
|
||||
//rest api to delete record from mysql database
|
||||
/*server.delete('/employees/:id', function (req, res) {
|
||||
connection.query('DELETE FROM `employee` WHERE `id`=?', [req.params.id], function (error, results, fields) {
|
||||
if (error) throw error;
|
||||
res.end('Record has been deleted!');
|
||||
});
|
||||
});*/
|
||||
|
||||
server.get('/', function(req, res){
|
||||
console.log('Welcome Nodejs restify');
|
||||
});
|
||||
|
||||
server.listen(3001, function () {
|
||||
console.log('%s listening at %s', server.name, server.url);
|
||||
});
|
16
package.json
Executable file
16
package.json
Executable file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "nodejs-restapi-example",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"mysql": "^2.14.1",
|
||||
"restify": "^5.2.0"
|
||||
}
|
||||
}
|
65
server.js
Executable file
65
server.js
Executable file
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 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(){
|
||||
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(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);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user