Skip to content

Commit

Permalink
Merge branch 'feature/#26-code-formatting'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoupey committed May 14, 2019
2 parents 3f096f7 + 59242be commit e532a55
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 140 deletions.
58 changes: 58 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"env": {
"browser": true,
"node": true
},
"plugins": ["prettier"],
"extends": ["prettier"],
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"curly": 2,
"dot-notation": 2,
"id-length": 1,
"no-const-assign": 2,
"no-dupe-class-members": 2,
"no-else-return": 2,
"no-inner-declarations": 2,
"no-lonely-if": 2,
"no-magic-numbers": [
2,
{
"ignore": [-1, 0, 1, 2]
}
],
"no-shadow": 2,
"no-unneeded-ternary": 2,
"no-unused-expressions": 2,
"no-unused-vars": [
2,
{
"args": "none"
}
],
"no-useless-return": 2,
"no-var": 2,
"one-var": [2, "never"],
"prefer-arrow-callback": 2,
"prefer-const": 2,
"prefer-promise-reject-errors": 2,
"prettier/prettier": 2,
"sort-imports": 2,
"sort-keys": [
2,
"asc",
{
"caseSensitive": true,
"natural": true
}
],
"sort-vars": 2,
"strict": [2, "global"]
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/node_modules
access.log
yarn.lock
package-lock.json
Empty file added .prettierignore
Empty file.
22 changes: 22 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"arrowParens": "avoid",
"bracketSpacing": false,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"jsxBracketSameLine": false,
"printWidth": 80,
"proseWrap": "preserve",
"requirePragma": false,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"overrides": [
{
"files": "*.json",
"options": {
"printWidth": 200
}
}
]
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ npm install
# Usage

Run the server using:

```bash
npm start
```
Expand Down
33 changes: 31 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
"version": "0.1.0",
"description": "An express server to expose VROOM as a web API.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src/index.js"
"test": "npm run-script test:other && npm run-script test:js",
"start": "node src/index.js",
"fix:other": "npm run-script -- prettier --write",
"fix:js": "npm run-script -- test:js --fix",
"fix": "npm run-script fix:js && npm run-script fix:other",
"prettier": "prettier \"**/*.{json,md,scss,yaml,yml}\"",
"test:other": "npm run-script -- prettier --list-different",
"test:js": "eslint --ignore-path .gitignore --ignore-path .prettierignore \"**/*.{js,jsx}\""
},
"keywords": [
"VROOM",
Expand All @@ -31,5 +37,28 @@
"repository": {
"type": "git",
"url": "https://github.com/VROOM-Project/vroom-express.git"
},
"devDependencies": {
"eslint": "5.16.0",
"eslint-config-prettier": "4.2.0",
"eslint-plugin-prettier": "3.0.1",
"husky": "2.2.0",
"lint-staged": "8.1.6",
"prettier": "1.17.0"
},
"lint-staged": {
"*.{js,jsx}": [
"eslint --fix",
"git add"
],
"*.{json,md,scss,yaml,yml}": [
"prettier --write",
"git add"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
61 changes: 37 additions & 24 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
"use strict";
const minimist = require('minimist');

var minimist = require("minimist");
const TIMEOUT = 5 * 60 * 1000; // eslint-disable-line
const MAX_JOBS = 1000;
const MAX_VEHICLES = 200;
const MAX_REQUEST_SIZE = '1mb';
const PORT = 3000;
const LOG_DIR = __dirname + '/..';
const ROUTER = 'osrm';

// Config variables.
var cliArgs = minimist(process.argv.slice(2), {
const cliArgs = minimist(process.argv.slice(2), {
alias: {
p: "port",
r: "router"
p: 'port', // eslint-disable-line
r: 'router', // eslint-disable-line
},
boolean: ["geometry", "override"],
boolean: ['geometry', 'override'],
default: {
port: 3000, // expressjs port
path: "", // VROOM path (if not in $PATH)
maxjobs: "1000", // max number of jobs
maxvehicles: "200", // max number of vehicles
geometry: false, // retrieve geometry (-g)
router: "osrm", // routing backend (osrm, libosrm or ors)
limit: MAX_REQUEST_SIZE, // max request size
logdir: LOG_DIR, // put logs in there
maxjobs: MAX_JOBS, // max number of jobs
maxvehicles: MAX_VEHICLES, // max number of vehicles
override: true, // allow cl option override (-g only so far)
logdir: __dirname + "/..", // put logs in there
limit: "1mb", // max request size
timeout: 5 * 60 * 1000 // milli-seconds.
path: '', // VROOM path (if not in $PATH)
port: PORT, // expressjs port
router: ROUTER, // routing backend (osrm, libosrm or ors)
timeout: TIMEOUT // milli-seconds.
}
});

// For each routing profile add a host and a port for use with osrm
// and ors.
var routingServers = {
const routingServers = {
car: {
host: "0.0.0.0",
port: "5000"
host: '0.0.0.0',
port: '5000'
}
};

const VROOM_OK_CODE = 0;
const VROOM_INTERNALERROR_CODE = 1;
const VROOM_INPUTERROR_CODE = 2;
const VROOM_ROUTINGERROR_CODE = 3;
const VROOM_TOOLARGE_CODE = 4;

// Hard-code error codes 1, 2 and 3 as defined in vroom. Add 4 code
// for size checks.
var errorCodes = {
internal: 1,
input: 2,
routing: 3,
tooLarge: 4
const vroomErrorCodes = {
input: VROOM_INPUTERROR_CODE,
internal: VROOM_INTERNALERROR_CODE,
ok: VROOM_OK_CODE,
routing: VROOM_ROUTINGERROR_CODE,
tooLarge: VROOM_TOOLARGE_CODE
};

module.exports = {
errorCodes: errorCodes,
cliArgs: cliArgs,
routingServers: routingServers
routingServers: routingServers,
vroomErrorCodes: vroomErrorCodes
};
Loading

0 comments on commit e532a55

Please sign in to comment.