Merge pull request #60 from KevinMidboe/lint

Lint
This commit is contained in:
2017-10-26 14:53:06 +02:00
committed by GitHub
7 changed files with 59 additions and 49 deletions

View File

@@ -0,0 +1,3 @@
{
"extends": "airbnb-base"
}

View File

@@ -2,12 +2,14 @@
"name": "seasoned-api",
"main": "webserver/server.js",
"scripts": {
"start": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. node src/webserver/server.js"
"start": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. node src/webserver/server.js",
"lint": "./node_modules/.bin/eslint src/webserver/"
},
"dependencies": {
"bcrypt-nodejs": "^0.0.3",
"body-parser": "~1.0.1",
"cross-env": "^3.1.3",
"eslint": "^4.9.0",
"express": "~4.0.0",
"jsonwebtoken": "^8.0.1",
"mongoose": "^3.6.13",
@@ -19,5 +21,9 @@
"request-promise": "^4.2",
"sqlite": "^2.2.1",
"sqlite3": "^2.5.0"
},
"devDependencies": {
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.8.0"
}
}

View File

@@ -1,10 +1,9 @@
var express= require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');
const express = require('express');
const bodyParser = require('body-parser');
const tokenToUser = require('./middleware/tokenToUser');
const mustBeAuthenticated = require('./middleware/mustBeAuthenticated');
const app = express(); // define our app using express
// this will let us get the data from a POST
// configure app to use bodyParser()
app.use(bodyParser.json());
@@ -14,9 +13,9 @@ app.use(bodyParser.json());
/* Decode the Authorization header if provided */
// router.use(tokenToUser);
var port = 31459; // set our port
var router = express.Router();
var allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080']
const port = 31459; // set our port
const router = express.Router();
const allowedOrigins = ['https://kevinmidboe.com', 'http://localhost:8080'];
// router.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
@@ -25,23 +24,23 @@ app.use(bodyParser.urlencoded({ extended: true }));
/* Decode the Authorization header if provided */
router.use(tokenToUser);
router.use(function(req, res, next) {
// TODO add logging of all incoming
console.log('Request: ', req.originalUrl);
var origin = req.headers.origin;
if (allowedOrigins.indexOf(origin) > -1) {
console.log('allowed');
res.setHeader('Access-Control-Allow-Origin', origin);
}
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, loggedinuser');
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT');
next();
router.use((req, res, next) => {
// TODO add logging of all incoming
console.log('Request: ', req.originalUrl);
const origin = req.headers.origin;
if (allowedOrigins.indexOf(origin) > -1) {
console.log('allowed');
res.setHeader('Access-Control-Allow-Origin', origin);
}
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, loggedinuser');
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT');
next();
});
router.get('/', function(req, res) {
res.json({ message: 'hooray! welcome to this api!' });
});
router.get('/', ((req, res) => {
res.json({ message: 'hooray! welcome to this api!' });
}));
/**
* User
@@ -51,7 +50,7 @@ router.post('/v1/user/login', require('./controllers/user/login.js'));
router.get('/v1/user/history', mustBeAuthenticated, require('./controllers/user/history.js'));
/**
* Seasoned
* Seasoned
*/
router.get('/v1/seasoned/all', require('./controllers/seasoned/readStrays.js'));
router.get('/v1/seasoned/:strayId', require('./controllers/seasoned/strayById.js'));

View File

@@ -1,15 +1,15 @@
const configuration = require('src/config/configuration').getInstance();
const GitRepository = require('src/git/gitRepository');
const gitRepository = new GitRepository();
function dumpHookController(req, res) {
gitRepository.dumpHook(req.body)
.then(() => {
res.status(200);
})
.catch((error) => {
res.status(500);
})
gitRepository.dumpHook(req.body)
.then(() => {
res.status(200);
})
.catch((error) => {
res.status(500);
});
}
module.exports = dumpHookController;

View File

@@ -1,4 +1,5 @@
const RequestRepository = require('src/plex/requestRepository.js');
const requestRepository = new RequestRepository();
/**
@@ -11,12 +12,12 @@ function historyController(req, res) {
const user = req.loggedInUser;
requestRepository.fetchRequested()
.then((requestedItems) => {
res.send({ success: true, requestedItems });
})
.catch((error) => {
res.status(401).send({ success: false, error: error.message });
});
.then((requestedItems) => {
res.send({ success: true, requestedItems });
})
.catch((error) => {
res.status(401).send({ success: false, error: error.message });
});
}
module.exports = historyController;

View File

@@ -1,16 +1,17 @@
const StrayRepository = require('src/seasoned/strayRepository');
const strayRepository = new StrayRepository();
function verifyStrayController(req, res) {
const id = req.params.strayId;
const id = req.params.strayId;
strayRepository.verifyStray(id)
.then(() => {
res.send({ success: true, message: 'Episode verified' });
})
.catch((error) => {
res.status(500).send({ success: false, error: error.message });
});
strayRepository.verifyStray(id)
.then(() => {
res.send({ success: true, message: 'Episode verified' });
})
.catch((error) => {
res.status(500).send({ success: false, error: error.message });
});
}
module.exports = verifyStrayController;

View File

@@ -2,7 +2,7 @@ const config = require('src/config/configuration').getInstance();
const app = require('./app');
module.exports = app.listen(config.get('webserver', 'port'), () => {
console.log('seasonedAPI');
console.log(`Database is located at ${config.get('database', 'host')}`);
console.log(`Webserver is listening on ${config.get('webserver', 'port')}`);
console.log('seasonedAPI');
console.log(`Database is located at ${config.get('database', 'host')}`);
console.log(`Webserver is listening on ${config.get('webserver', 'port')}`);
})