Skip to content

Commit

Permalink
Add stable codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
vs4vijay committed Mar 12, 2020
1 parent f3daee6 commit 2e439be
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/

.git

*.log

*.env
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV=development
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "plugin:prettier/recommended",
"parserOptions": {
"ecmaVersion": 6
}
}
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"tabWidth": 2
}
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:10.10.0-alpine

WORKDIR /app

COPY package*.json ./

# USER node

RUN npm install

COPY . ./
# COPY --chown=node:node . ./

ENV APP_PORT 9999

EXPOSE ${APP_PORT}

CMD ["node", "src/app.js"]
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# Karma
# Karma



---

### Development Notes

```
Redis
Dockerize
CI/CD
Kubernetes
Spinnaker
```
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "Karma",
"version": "1.0.0",
"main": "app.js",
"repository": "[email protected]:vs4vijay/Karma.git",
"author": "Vijay Soni <[email protected]>",
"license": "MIT",
"scripts": {
"start": "node src/app.js",
"dev": "nodemon src/app.js",
"lint": "eslint ."
},
"dependencies": {
"dotenv": "^8.2.0",
"express": "^4.17.1"
},
"devDependencies": {
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-prettier": "^3.1.1",
"nodemon": "^1.19.2",
"prettier": "^1.18.2"
}
}
51 changes: 51 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env node
'use strict';

const express = require('express');

const { CONFIG } = require('./config');
const { healthCheckRouter } = require('./controllers');

const app = express();

app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.get('/', function(req, res, next) {
res.json({
success: true,
message: 'Server is Running'
});
});

// Adding routes
app.use(CONFIG['BASE_PATH'], healthCheckRouter);

// Adding 404 route
app.get('*', (req, res) => {
res.status(404).json({ success: false, message: 'Resource not found' });
});

app.use(function(error, req, res, next) {
console.error(error.stack);

const response = {
success: false,
errors: error.stack
};
res.status(500).json(response);
});

if (require.main == module) {
app.listen(CONFIG['PORT'], _ => {
console.log(`[+] App Server started on ${CONFIG['PORT']}`);
});
}

process.on('SIGINT', function() {
process.exit();
});

module.exports = {
app
};
13 changes: 13 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

require('dotenv').config();

const CONFIG = {
PORT: process.env.PORT || 9999,
BASE_PATH: '/api/v1',
TIMESTAMP: new Date().toTimeString()
};

module.exports = {
CONFIG
};
22 changes: 22 additions & 0 deletions src/controllers/health-check.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const express = require('express');

const { CONFIG } = require('../config');

const healthCheckRouter = express.Router();

healthCheckRouter.get('/health_check', (req, res) => {
console.log('health_check');

const response = {
success: true,
health_check: true,
timestamp: CONFIG['TIMESTAMP']
};
res.json(response);
});

module.exports = {
healthCheckRouter
};
7 changes: 7 additions & 0 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const { healthCheckRouter } = require('./health-check.controller');

module.exports = {
healthCheckRouter
};
3 changes: 3 additions & 0 deletions src/services/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = { };

0 comments on commit 2e439be

Please sign in to comment.