From 686186b3065dcae630daa81817f135997e92be74 Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Thu, 11 May 2017 18:36:32 +0200 Subject: [PATCH] Fix node script start; Fix squad-model sortingNumber max; Refractor config path --- .gitignore | 3 --- api/{routes => config}/api-url.js | 0 api/{ => config}/config.js | 3 +-- api/middleware/auth-middleware.js | 2 +- api/models/squad.js | 1 - api/routes/authenticate.js | 2 +- api/routes/squads.js | 2 +- api/server.js | 21 ++++++++++--------- api/test/awardings.spec.js | 2 +- api/test/command.spec.js | 2 +- api/test/config/spec_helper.js | 2 +- api/test/content-tool/user-db-item-creator.js | 2 +- api/test/decorations.spec.js | 2 +- api/test/ranks.spec.js | 2 +- api/test/squads.spec.js | 2 +- api/test/users.spec.js | 2 +- package.json | 8 +++---- 17 files changed, 27 insertions(+), 31 deletions(-) rename api/{routes => config}/api-url.js (100%) rename api/{ => config}/config.js (75%) diff --git a/.gitignore b/.gitignore index f6daf6e..8cdc446 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ # See http://help.github.com/ignore-files/ for more about ignoring files. -# external project -/rest-server - # compiled output /dist /tmp diff --git a/api/routes/api-url.js b/api/config/api-url.js similarity index 100% rename from api/routes/api-url.js rename to api/config/api-url.js diff --git a/api/config.js b/api/config/config.js similarity index 75% rename from api/config.js rename to api/config/config.js index b599ca3..549212b 100644 --- a/api/config.js +++ b/api/config/config.js @@ -1,11 +1,10 @@ module.exports = { port: 8091, - secret: "!78sg7gu/fdi78(G/bgu=lö'+++c:4863", + secret: "$8h94j+8z4trh%nj+18tj!h4gf8zuƢzf4zjt(16", database: { uri: 'mongodb://localhost:27017/', db: 'cc', - }, test: { diff --git a/api/middleware/auth-middleware.js b/api/middleware/auth-middleware.js index bff8c8a..c9f811a 100644 --- a/api/middleware/auth-middleware.js +++ b/api/middleware/auth-middleware.js @@ -1,7 +1,7 @@ "use strict" const jwt = require('jsonwebtoken'); -const config = require('../config'); +const config = require('../config/config'); const apiAuthentication = (req, res, next) => { diff --git a/api/models/squad.js b/api/models/squad.js index e0f5394..e427fd6 100644 --- a/api/models/squad.js +++ b/api/models/squad.js @@ -15,7 +15,6 @@ const SquadSchema = new Schema({ }, sortingNumber: { type: Number, - max: 22, get: v => Math.round(v), set: v => Math.round(v), default: 0 diff --git a/api/routes/authenticate.js b/api/routes/authenticate.js index 398cd03..3c56f66 100644 --- a/api/routes/authenticate.js +++ b/api/routes/authenticate.js @@ -11,7 +11,7 @@ const logger = require('debug')('cc:authenticate'); // HTTP status codes by name const codes = require('./http-codes'); -const config = require('../config'); +const config = require('../config/config'); const routerHandling = require('../middleware/router-handling'); diff --git a/api/routes/squads.js b/api/routes/squads.js index f73a02e..7ad10ee 100644 --- a/api/routes/squads.js +++ b/api/routes/squads.js @@ -29,7 +29,7 @@ squads.route('/') if (req.query.q) { filter.name = {$regex: req.query.q, $options: 'i'} } - SquadModel.find(filter, {}, {sort: {fraction: 'asc', name: 'asc'}}, (err, items) => { + SquadModel.find(filter, {}, {sort: {sortingNumber: 'asc', fraction: 'asc'}}, (err, items) => { if (err) { err.status = codes.servererror; return next(err); diff --git a/api/server.js b/api/server.js index 8219541..4bd0e3f 100644 --- a/api/server.js +++ b/api/server.js @@ -9,7 +9,8 @@ const debug = require('debug')('cc:server'); const mongoose = require('mongoose'); // own modules -const config = require('./config'); +const config = require('./config/config'); +const urls = require('./config/api-url'); const restAPIchecks = require('./middleware/request-checks.js'); const errorResponseWare = require('./middleware/error-response'); const apiAuthenticationMiddleware = require('./middleware/auth-middleware'); @@ -48,17 +49,17 @@ app.use(restAPIchecks); // Routes ****************************************************** -app.use('/authenticate', authenticateRouter); -app.use('/signatures', signatureRouter); +app.use(urls.auth, authenticateRouter); +app.use(urls.signatures, signatureRouter); // all following routes need a jwt token to access -app.use('/overview', overviewRouter); -app.use('/users', userRouter); -app.use('/squads', squadRouter); -app.use('/ranks', rankRouter); -app.use('/decorations', decorationRouter); -app.use('/awardings', apiAuthenticationMiddleware, awardingRouter); -app.use('/cmd', apiAuthenticationMiddleware, commandRouter); +app.use(urls.overview, overviewRouter); +app.use(urls.users, userRouter); +app.use(urls.squads, squadRouter); +app.use(urls.ranks, rankRouter); +app.use(urls.decorations, decorationRouter); +app.use(urls.awards, apiAuthenticationMiddleware, awardingRouter); +app.use(urls.command, apiAuthenticationMiddleware, commandRouter); // send index.html on all different paths app.use(function (req, res) { diff --git a/api/test/awardings.spec.js b/api/test/awardings.spec.js index 661cb92..2811a28 100644 --- a/api/test/awardings.spec.js +++ b/api/test/awardings.spec.js @@ -1,6 +1,6 @@ let mongoose = require("mongoose"); let AwardingModel = require('../models/awarding'); -let urls = require('../routes/api-url'); +let urls = require('../config/api-url'); let codes = require('../routes/http-codes'); diff --git a/api/test/command.spec.js b/api/test/command.spec.js index ec0c7fd..bff2b18 100644 --- a/api/test/command.spec.js +++ b/api/test/command.spec.js @@ -1,6 +1,6 @@ let mongoose = require("mongoose"); let AwardingModel = require('../models/awarding'); -let urls = require('../routes/api-url'); +let urls = require('../config/api-url'); let codes = require('../routes/http-codes'); diff --git a/api/test/config/spec_helper.js b/api/test/config/spec_helper.js index e11f84f..430e88b 100644 --- a/api/test/config/spec_helper.js +++ b/api/test/config/spec_helper.js @@ -1,3 +1,3 @@ -const config = require('../../config'); +const config = require('../../config/config'); process.env.NODE_ENV = config.test.env; diff --git a/api/test/content-tool/user-db-item-creator.js b/api/test/content-tool/user-db-item-creator.js index 8d8aaad..26bcf6a 100644 --- a/api/test/content-tool/user-db-item-creator.js +++ b/api/test/content-tool/user-db-item-creator.js @@ -1,4 +1,4 @@ -const config = require('../../config'); +const config = require('../../config/config'); const mongoose = require('mongoose'); mongoose.connect(config.database.uri + config.database.db); const UserModel = require('../../models/user'); diff --git a/api/test/decorations.spec.js b/api/test/decorations.spec.js index 9ebc5c9..a140255 100644 --- a/api/test/decorations.spec.js +++ b/api/test/decorations.spec.js @@ -1,6 +1,6 @@ let mongoose = require("mongoose"); let DecorationModel = require('../models/decoration'); -let urls = require('../routes/api-url'); +let urls = require('../config/api-url'); let codes = require('../routes/http-codes'); diff --git a/api/test/ranks.spec.js b/api/test/ranks.spec.js index 1071369..a3236b3 100644 --- a/api/test/ranks.spec.js +++ b/api/test/ranks.spec.js @@ -1,6 +1,6 @@ let mongoose = require("mongoose"); let RankModel = require('../models/rank'); -let urls = require('../routes/api-url'); +let urls = require('../config/api-url'); let codes = require('../routes/http-codes'); diff --git a/api/test/squads.spec.js b/api/test/squads.spec.js index d7507c9..82c8f47 100644 --- a/api/test/squads.spec.js +++ b/api/test/squads.spec.js @@ -1,6 +1,6 @@ let mongoose = require("mongoose"); let SquadModel = require('../models/squad'); -let urls = require('../routes/api-url'); +let urls = require('../config/api-url'); let codes = require('../routes/http-codes'); diff --git a/api/test/users.spec.js b/api/test/users.spec.js index 78d1f38..09727f7 100644 --- a/api/test/users.spec.js +++ b/api/test/users.spec.js @@ -1,7 +1,7 @@ let mongoose = require("mongoose"); let UserModel = require('../models/user'); let AppUserModel = require('../models/app-user'); -let urls = require('../routes/api-url'); +let urls = require('../config/api-url'); let codes = require('../routes/http-codes'); diff --git a/package.json b/package.json index beab813..afff3ca 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "license": "MIT", "private": true, "scripts": { - "start": "npm run deploy-static-prod && node ./rest-server/server.js", - "dev": "npm run deploy-static && nodemon api/server.js", - "deploy-static": "cd static && ng build && ln -s ../api/resource/ ../public/resource", - "deploy-static-prod": "cd static && ng build --env=prod && ln -s ../api/resource/ ../public/resource", + "start": "npm run deploy-static-prod && node ./api/server.js", + "dev": "npm run deploy-static && nodemon ./api/server.js", + "deploy-static": "cd ./static && ng build && ln -s ../api/resource/ ../public/resource", + "deploy-static-prod": "cd ./static && ng build --env=prod && ln -s ../api/resource/ ../public/resource", "postinstall": "npm install --prefix ./static && npm install --prefix ./api", "mongodb": "mongod --dbpath ./mongodb-data", "test": "npm test --prefix ./api"