initial cmt : suseendhiran

This commit is contained in:
suseendhiran17 2022-09-07 09:33:23 +05:30
parent 801bc93134
commit 6d045ea1a5
11 changed files with 23732 additions and 50 deletions

53
.gitignore vendored
View File

@ -1,50 +1,3 @@
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
# Node artifact files
node_modules/
dist/
# Compiled Java class files
*.class
# Compiled Python bytecode
*.py[cod]
# Log files
*.log
# Package files
*.jar
# Maven
target/
dist/
# JetBrains IDE
.idea/
# Unit test reports
TEST*.xml
# Generated by MacOS
.DS_Store
# Generated by Windows
Thumbs.db
# Applications
*.app
*.exe
*.war
# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv
/node_modules
/storage
.env

16
app/config/db.config.js Normal file
View File

@ -0,0 +1,16 @@
require('dotenv').config();
const { logMsg } = require('../services/logger');
module.exports = {
"development": {
"username": process.env.USER_NAME,
"password": process.env.PASSWORD,
"database": process.env.DATABASE,
"port": process.env.PORT,
"host": process.env.HOST,
"dialect": "mssql",
"logging": (message) =>(logMsg.info(message))
}
};

View File

@ -0,0 +1,96 @@
const { sequelize } = require('../models')
const TestHelper = require('../services/test.helper.js');
const { logMsg } = require('../services/logger.js');
const request = require('request');
// api status check Api
exports.APIstatus = async (req, res) =>
{
try
{
apiArr = [ ];
serverArr = [ ];
StatusFailArr = [ ];
ApiData = JSON.parse(process.env.STATUSARRAY);
token_data = await TestHelper.TokenAPI();
if (token_data.status == 200) { apiArr.push({ "Api" : "Token Api" , "StatusCode" : token_data.status , "Status" : "Up"}); }
else { arr.push({ "Api" : "Token Api" , "StatusCode" : token_data.status , "Status" : "Down"}); StatusFailArr.push(token_data.status) }
for (const object of ApiData)
{
reqObj = { };
URL = object.url;
request_object = object.requestObject;
request_header = "Bearer"+" "+token_data.data.token;
if (object.header == 1) { reqObj = {url: URL, method: object.method,json: true,body: request_object,headers : { 'Content-Type' : 'application/json' , 'Authorization' : request_header }} }
else { reqObj = {url: URL,method: object.method,json: true,body: request_object} }
request(reqObj, async function (error, response, body) {
if (response.statusCode == 200)
{
if (object.type == "api") { apiArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Up"}); }
else { serverArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Up"}); }
}
if (response.statusCode != 200)
{
if (object.type == "api") { apiArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Down"}); StatusFailArr.push(token_data.status) }
else { serverArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Down"}); StatusFailArr.push(token_data.status) }
}
if (ApiData.length + 1 == apiArr.length + serverArr.length) {
await TestHelper.HTML( req , res , apiArr , serverArr , StatusFailArr );
}
})
};
}
catch(err)
{
res.send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
});
} //end of try catch
};
// Single Api status check Api
exports.SingleApiStatus = async (req, res) =>
{
try
{
ApiName = req.body.api;
ApiData = JSON.parse(process.env.STATUSARRAY);
token_data = await TestHelper.TokenAPI();
if (ApiName == "Token Api")
{
if (token_data.status == 200) { res.send({ "Api" : "Token Api" , "StatusCode" : token_data.status , "Status" : "Up" , "success" : true}) }
else { res.send({ "Api" : "Token Api" , "StatusCode" : token_data.status , "Status" : "Down" , "success" : true}) }
}
else
{
ApiData.forEach(async(object) =>
{
if (ApiName == object.name)
{
reqObj = { };
URL = object.url;
request_object = object.requestObject;
request_header = "Bearer"+" "+token_data.data.token;
if (object.header == 1) { reqObj = {url: URL, method: object.method,json: true,body: request_object,headers : { 'Content-Type' : 'application/json' , 'Authorization' : request_header }} }
else { reqObj = {url: URL,method: object.method,json: true,body: request_object} }
request(reqObj, function (error, response, body) {
if (response.statusCode == 200) { res.send({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Up" , "success" : true}) }
else { res.send({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Down" , "success" : true}) }
})
}
});
}
}
catch(err)
{
res.send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
});
} //end of try catch
};

39
app/models/index.js Normal file
View File

@ -0,0 +1,39 @@
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/db.config.js')[env];
//console.log(env);
//console.log(config);
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;

25
app/routes/routes.js Normal file
View File

@ -0,0 +1,25 @@
module.exports = app => {
const request = require("request");
const cors=require('cors');
const Mycontroller = require("../controllers/test.controller.js");
const { logMsg } = require('../services/logger.js');
var router = require("express").Router();
// api status check Api
router.get("/APIstatus", Mycontroller.APIstatus);
// Single Api status check Api
router.post("/SingleApiStatus", Mycontroller.SingleApiStatus);
// routes started here
app.use('/api', router);
};

27
app/services/logger.js Normal file
View File

@ -0,0 +1,27 @@
/**
* Configurations of logger.
*/
var winston = require('winston');
require('winston-daily-rotate-file');
var transport = new winston.transports.DailyRotateFile({
filename: 'storage/log/msg.log',
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d'
});
transport.on('rotate', function(oldFilename, newFilename) {
// do something fun
});
const logger = winston.createLogger({
transports: [
transport
]
});
module.exports = {
'logMsg': logger,
};

View File

@ -0,0 +1,55 @@
const request = require('request');
function TokenAPI()
{
try
{
TOKEN_URL = process.env.URL_TOKEN;
return new Promise((resolve, reject) => {
request({
url: TOKEN_URL,
method: "GET",
json: true
}, function (error, response, body){
resolve(body);
});
});
}
catch (error) {
console.log(error);
}
}
function HTML( req , res , apiStatusArr , serverStatusArr , apiFailStatusArr )
{
try
{
date = new Date().toLocaleTimeString();
if (apiFailStatusArr.length == 0)
{
res.render( 'status' , { data : apiStatusArr , data1 : serverStatusArr , down : 0 , date : date } , function (err, html ) {
res.send(html)
})
}
else
{
res.render( 'status' , { data : apiStatusArr , data1 : serverStatusArr , down : 1 , date : date } , function (err, html ) {
res.send(html)
})
}
}
catch (error) {
console.log(error);
}
}
module.exports = {
TokenAPI : TokenAPI,
HTML : HTML
}

332
app/views/status.ejs Normal file
View File

@ -0,0 +1,332 @@
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
setInterval(function() {
window.location.reload();
}, 300000);
</script>
<style>
/* table, th, td {
border:1px solid rgb(20, 2, 2);
padding: 8px;
border-bottom: 1px solid #DDD;
text-align: center;
}
table {
border-collapse: collapse;
border: 2px solid #161614;
width: 87%;
}
th {
font-size: 20px;
}
th , h1 , td {
font-family: Arial, Helvetica, sans-serif;
} */
b {
font-family: Arial, Helvetica, sans-serif;
color: #3bd671 !important
}
.dot {
height: 25px;
width: 25px;
background-color: lightgreen;
border-radius: 90%;
display: inline-block;
cursor: pointer;
box-shadow: 0 0 0 rgba(204,169,44, 0.4);
animation: pulse 2s infinite;
}
.dot:hover {
animation: none;
}
.dot1 {
height: 25px;
width: 25px;
background-color: red;
border-radius: 90%;
display: inline-block;
cursor: pointer;
box-shadow: 0 0 0 rgba(204,169,44, 0.4);
animation: pulse 2s infinite;
}
.dot1:hover {
animation: none;
}
@-webkit-keyframes pulse {
0% {
-webkit-box-shadow: 0 0 0 0 rgba(204,169,44, 0.4);
}
70% {
-webkit-box-shadow: 0 0 0 10px rgba(204,169,44, 0);
}
100% {
-webkit-box-shadow: 0 0 0 0 rgba(204,169,44, 0);
}
}
@keyframes pulse {
0% {
-moz-box-shadow: 0 0 0 0 rgba(204,169,44, 0.4);
box-shadow: 0 0 0 0 rgba(204,169,44, 0.4);
}
70% {
-moz-box-shadow: 0 0 0 10px rgba(204,169,44, 0);
box-shadow: 0 0 0 10px rgba(204,169,44, 0);
}
100% {
-moz-box-shadow: 0 0 0 0 rgba(204,169,44, 0);
box-shadow: 0 0 0 0 rgba(204,169,44, 0);
}
}
.header {
background: rgb(3, 37, 37);
padding: 10px 0;
height: 20%;
width: 100%;
}
.with-in-header{
color: white;
text-align: right;
position: relative;
right: 70px;
padding-left: 2em;
}
.last-update{
color: white;
font-size: large;
text-align: right;
position: relative;
right: 70px;
padding-left: 2em;
}
.header1 {
background: white;
border-radius: 6px;
/* border: 2px solid #1f221c; */
text-align: left;
padding: 10px 0;
padding-top: 2em;
padding-left: 2em;
height: 40%;
width: 70%;
position: relative;
left: 220px;
top: 30px;
}
.header2 {
background: white;
text-align: left;
padding: 10px 0;
width: 80%;
position: relative;
left: 220px;
top: 100px;
}
.header3 {
background: white;
text-align: left;
padding: 10px 0;
width: 80%;
position: relative;
left: 220px;
top: 100px;
}
.header4 {
background: white;
text-align: left;
padding: 10px 0;
width: 80%;
position: relative;
left: 220px;
top: 100px;
}
.header5 {
background: white;
text-align: left;
padding: 10px 0;
width: 80%;
position: relative;
left: 220px;
top: 100px;
}
.uk-text-primary {
color: #3bd671 !important;
}
.uk-text-primary1 {
color: red;
font-family: Arial, Helvetica, sans-serif;
}
#tab-des {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 87%;
}
#tab-des td, #tab-des th {
border: 1px solid #ddd;
width: 0em;
padding: 8px;
}
#tab-des tr:nth-child(even){background-color: #f2f2f2;}
#tab-des tr:hover {background-color: #ddd;}
#tab-des th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #04AA6D;
color: white;
}
#tab-des-2 {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 87%;
top: 100px;
}
#tab-des-2 td, #tab-des-2 th {
border: 1px solid #ddd;
width: 0em;
padding: 8px;
}
#tab-des-2 tr:nth-child(even){background-color: #f2f2f2;}
#tab-des-2 tr:hover {background-color: #ddd;}
#tab-des-2 th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #04AA6D;
color: white;
}
</style>
<title class="bi-alarm">Status</title>
<% if ( down == 0) { %>
<link rel="icon" type ="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAACK5JREFUeF7tW1uMVVcZ/r619zlzYZiZznDpIANUGCgFym1SoEUzvpioiTE1fTJpNI0+1CBgkTfNeVSspZdoIi8ao5GEl5pGjSbqFCUtpRQpDMNlGqDAlNsAnWGYmXPOXp9Z+zB0gOnsvc9lMIX9ePZae63v+6/r/9ch7vOH9zl+PCDggQbc5ww8MIH7XAEeOMH/CxN4Rs94H78/t3rAD6qq4KdzHs2dminf5tMD+SwaG4c752VGQKgc2nvPCFj97vdS3pRUfRpVzaLqEaAGNNWAUqS828FRMjaQMOIBI0GAQdC7GqSyV+csOD+4i7uCYsmYXAIEdhx5fsqwSU8zQIugeoq+4ViJcwLJ6tZ+JQaEsoHY59Oev6LGvq4lmWxSIiaNgI6TmWo7cr0lb3OthFdXkPJEYONCEUHkLG1fOp8+g4tTLnd+KZOPO7vyBChj1hy+Oj2d4gJrTUP5gN/lJUIiQH6UM7mTe9te649DQkUJWNKVSdf7A5+ntXMMUFUeiUfDsgr6aap69iyqPQ9m7EQzKkbAlw9umTKUyi8KgJaCjZdD3aPBF0aIAWwW1nxQdbHh1EQmURECOrqer8uxeimJaXG3XIlxLnIExKlc/42e/e07cuOtUXYCnOQHU3YZqemTK/XxKZRgA9+ebG07d3y8cFlWApzNN/Ha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ad1y5253kR+BhSPAHADuQ9dPXp35YM5jkZvikhcEkErg1VhnT0QlzaQbMnHTfXYL5MNus6RdhOzsyQbn+LXLPNaAooso86Z6aQJmxFPW5BwQURdtnaNJ9rwH/A01X6IyC8LngAAAAAElFTkSuQmCC">
<% } %>
<!-- <% if ( down == 1) { %>
<link rel="stylesheet" type ="text/css" href="//static.zohocdn.com/chat/source/officechat/styles/loadingpage-min.243202ee25f1a5bb3db367d2338ab25e.css">
<% } %> -->
</head>
<body>
<div class = "header">
<div>
<h1 class="with-in-header">Service status</h1>
<div class="last-update">
Last updated <%=date %>
</div>
</div>
<div class = "header1">
<% if ( down == 0) { %>
<h1><i class="dot" aria-hidden = "true" style="font-size:26px;color:lightgreen"></i> <strong> All systems
<span class="uk-text-primary">operational</span></strong></h1>
<% } %>
<% if ( down == 1) { %>
<h1><i class="dot1" aria-hidden = "true" style="font-size:26px;color:red"></i> <strong> Some systems are
<span class="uk-text-primary1">down</span></strong></h1>
<% } %>
</div>
</div>
<div class = "header2"><h1><i style="font-size:18px;color:black"></i> <strong>Api Services</strong></h1></div>
<div class = "header3">
<table id="tab-des">
<thead>
<tr>
<th>Api</th>
<th>StatusCode</th>
<th>Status</th>
<th>Refresh</th>
</tr>
</thead>
<% data.forEach(function(status , index ) { %>
<tbody>
<tr class=index>
<td><%=status.Api %></td>
<td><%=status.StatusCode %></td>
<td>
<% if( status.Status == "Up") { %>
<i class="dot" style="font-size:14px;color: #3bd671 !important;height:15px;width:15px;"></i> <b><%=status.Status %></b>
<% } %>
<% if( status.Status == "Down") { %>
<i class="dot1" style="font-size:14px;color: red;height:15px;width:15px;"></i> <b1><%=status.Status %></b1>
<% } %>
</td>
<td><a href="#" class="btn btn-info btn-sm" style="color: white;background-color: #3bd671 !important;">Refresh</a></td>
</tr>
</tbody>
<% }) %>
</table>
</div>
<div class = "header4"><h1><i style="font-size:18px;color:black"></i> <strong>Server Services</strong></h1></div>
<div class = "header5">
<table id="tab-des-2">
<thead>
<tr>
<th>Server</th>
<th>StatusCode</th>
<th>Status</th>
<th>Refresh</th>
</tr>
</thead>
<% data1.forEach(function(status , index ) { %>
<tbody>
<tr class=index>
<td><%=status.Api %></td>
<td><%=status.StatusCode %></td>
<td>
<% if( status.Status == "Up") { %>
<i class="dot" style="font-size:14px;color: #3bd671 !important;height:15px;width:15px;"></i> <b><%=status.Status %></b>
<% } %>
<% if( status.Status == "Down") { %>
<i class="dot1" style="font-size:14px;color: red;height:15px;width:15px;"></i> <b1><%=status.Status %></b1>
<% } %>
</td>
<td><a href="#" class="btn btn-info btn-sm" style="color: white;background-color: #3bd671 !important;">Refresh</a></td>
</tr>
</tbody>
<% }) %>
</table>
</div>
</body>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.1.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script>
$(".index").click(function (evt) {
var api = $(evt.target).parent().parent("tr").find("td:nth-child(1)").text();
$.ajax({
type: "post",
url: "http://localhost:8888/api/SingleApiStatus",
data: {api : api},
success: function(response) {
if (response.success == true)
{
alert(response.Api+" called");
if (response.Status == "Up")
{
var success = '<i class="dot" style="font-size:14px;color: #3bd671 !important;height:15px;width:15px;"></i> <b>'+response.Status+'</b>'
}
else
{
var success = '<i class="dot1" style="font-size:14px;color: #3bd671 !important;height:15px;width:15px;"></i> <b>'+response.Status+'</b>'
}
$(evt.target).parent().parent("tr").find("td:nth-child(2)").html(response.StatusCode);
$(evt.target).parent().parent("tr").find("td:nth-child(3)").html(success);
}
},
error: function(jqXHR, textStatus, err) {
alert('text status '+textStatus+', err '+err)
}
});
});
</script>
</html>

23035
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

32
package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "node_mssql_project_setup",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"start": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"ejs": "^3.0.1",
"express": "^4.17.1",
"lodash": "^4.17.21",
"log4js": "^6.3.0",
"mssql": "^7.2.0",
"next-router": "^1.3.6",
"request": "^2.88.2",
"sequelize": "^6.6.5",
"swagger-jsdoc": "^6.1.0",
"swagger-ui-express": "^4.1.6",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5"
},
"devDependencies": {
"nodemon": "^2.0.12"
},
"description": ""
}

72
server.js Normal file
View File

@ -0,0 +1,72 @@
require('dotenv').config();
const express = require('express')
const bodyParser = require('body-parser');
const path = require('path');
const app = express()
app.set('views', path.join(__dirname, 'app\\views'));
app.set('view engine', 'ejs');
//it is used to clear cache
app.use(function(req, res, next) {
res.set("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0")
res.set("Pragma", "no-cache")
res.set("Expires", 0)
next()
})
const {logMsg} = require('./app/services/logger.js');
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Smc_cet_financials',
version: '1.0.0',
},
},
apis: ['./app/routes/routes.js'], // files containing annotations as above
};
const swaggerDocument = swaggerJsdoc(options);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
/**
* @openapi
* /:
* get:
* description: Welcome to swagger-jsdoc!
* responses:
* 200:
* description: Returns a mysterious string.
*/
app.get("/", (req, res) => {
console.log(path.join(__dirname, 'views'));
res.json({ message: "Welcome to the application." });
logMsg.info("Server Sent A Welcome to the application!");
});
app.use(express.json())
app.use(express.urlencoded({ extended: true }));
require("./app/routes/routes.js")(app);
const PORT_NUMBER = process.env.SERVER_PORT
app.listen({ port: PORT_NUMBER }, async () => {
console.log('Server up on http://localhost:'+PORT_NUMBER)
//await sequelize.authenticate()
})