structure changes
This commit is contained in:
parent
f5a5955656
commit
5175354aa3
.dockerignore.env.development.env.example.env.local.env.production.gitignoreDockerfiledocker-compose.dev.ymldocker-compose.prod.ymldocker-compose.ymlpackage.jsonyarn.lock
src
api/validations
configs
controllers
middlewares
models
routes/api/v1
services
authProviders.js
emails
tests/integration
utils
validations
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
combined.log
|
||||
error.log
|
@ -3,8 +3,7 @@ EMAIL_HOST=smtp.gmail.com
|
||||
EMAIL_PORT=587
|
||||
EMAIL_USERNAME=krish@sentientgeeks.com
|
||||
EMAIL_PASSWORD=123456
|
||||
NODE_ENV=development
|
||||
PORT=3000
|
||||
MONGO_URI_TESTS=mongodb://localhost:27017/sg-node-express-rest-api
|
||||
MONGO_URI=mongodb://localhost:27017/sg-node-express-rest-api
|
||||
# MONGO_URI_TESTS=mongodb://localhost:27017/sg-node-express-rest-api
|
||||
MONGO_URI=mongodb://mongo:27017/sg-node-express-rest-api
|
||||
JWT_EXPIRATION_MINUTES=300
|
10
.env.example
10
.env.example
@ -1,10 +0,0 @@
|
||||
JWT_SECRET=sajdhgjhasdhgads
|
||||
EMAIL_HOST=smtp.gmail.com
|
||||
EMAIL_PORT=587
|
||||
EMAIL_USERNAME=krish@sentientgeeks.com
|
||||
EMAIL_PASSWORD=123456
|
||||
NODE_ENV=development
|
||||
PORT=3000
|
||||
MONGO_URI_TESTS=mongodb://mongodb:27017/sg-node-express-rest-api
|
||||
MONGO_URI=mongodb://mongodb:27017/sg-node-express-rest-api
|
||||
JWT_EXPIRATION_MINUTES=300
|
@ -3,8 +3,7 @@ EMAIL_HOST=smtp.gmail.com
|
||||
EMAIL_PORT=587
|
||||
EMAIL_USERNAME=krish@sentientgeeks.com
|
||||
EMAIL_PASSWORD=123456
|
||||
NODE_ENV=development
|
||||
PORT=3000
|
||||
MONGO_URI_TESTS=mongodb://localhost:27017/sg-node-express-rest-api
|
||||
# MONGO_URI_TESTS=mongodb://localhost:27017/sg-node-express-rest-api
|
||||
MONGO_URI=mongodb://localhost:27017/sg-node-express-rest-api
|
||||
JWT_EXPIRATION_MINUTES=300
|
@ -3,8 +3,7 @@ EMAIL_HOST=smtp.gmail.com
|
||||
EMAIL_PORT=587
|
||||
EMAIL_USERNAME=krish@sentientgeeks.com
|
||||
EMAIL_PASSWORD=123456
|
||||
NODE_ENV=development
|
||||
PORT=3000
|
||||
MONGO_URI_TESTS=mongodb://localhost:27017/sg-node-express-rest-api
|
||||
MONGO_URI=mongodb://localhost:27017/sg-node-express-rest-api
|
||||
# MONGO_URI_TESTS=mongodb://localhost:27017/sg-node-express-rest-api
|
||||
MONGO_URI=mongodb://mongo:27017/sg-node-express-rest-api
|
||||
JWT_EXPIRATION_MINUTES=300
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ dist/
|
||||
coverage
|
||||
docs/
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
|
19
Dockerfile
19
Dockerfile
@ -1,14 +1,11 @@
|
||||
FROM node:8-alpine
|
||||
FROM node:latest
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ARG NODE_ENV
|
||||
ENV NODE_ENV $NODE_ENV
|
||||
|
||||
RUN mkdir /app
|
||||
WORKDIR /app
|
||||
ADD package.json yarn.lock /app/
|
||||
RUN yarn --pure-lockfile
|
||||
ADD . /app
|
||||
|
||||
CMD ["yarn", "docker:start"]
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["npm", "start"]
|
||||
|
||||
|
@ -1,6 +1,29 @@
|
||||
version: '2'
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
boilerplate-api:
|
||||
command: yarn dev -- -L
|
||||
node:
|
||||
container_name: nodejs-api
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
volumes:
|
||||
- .:/app
|
||||
depends_on:
|
||||
- mongo
|
||||
restart: always
|
||||
|
||||
mongo:
|
||||
container_name: mongodb
|
||||
image: mongo:latest
|
||||
ports:
|
||||
- "27017:27017"
|
||||
volumes:
|
||||
- mongo_data:/data/db
|
||||
restart: always
|
||||
|
||||
volumes:
|
||||
mongo_data:
|
||||
|
@ -1,6 +1,30 @@
|
||||
version: '2'
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
boilerplate-api:
|
||||
command: yarn start
|
||||
node:
|
||||
container_name: nodejs-api
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
volumes:
|
||||
- .:/app
|
||||
depends_on:
|
||||
- mongo
|
||||
restart: always
|
||||
|
||||
mongo:
|
||||
container_name: mongodb
|
||||
image: mongo:latest
|
||||
ports:
|
||||
- "27017:27017"
|
||||
volumes:
|
||||
- mongo_data:/data/db
|
||||
restart: always
|
||||
|
||||
|
||||
volumes:
|
||||
mongo_data:
|
@ -1,17 +0,0 @@
|
||||
version: '2'
|
||||
services:
|
||||
boilerplate-api:
|
||||
build: .
|
||||
environment:
|
||||
- MONGO_URI=mongodb://mongodb:27017/sg-node-express-rest-api
|
||||
volumes:
|
||||
- .:/app
|
||||
ports:
|
||||
- '3000:3000'
|
||||
depends_on:
|
||||
- mongodb
|
||||
|
||||
mongodb:
|
||||
image: mongo
|
||||
ports:
|
||||
- '27017:27017'
|
11
package.json
11
package.json
@ -4,14 +4,10 @@
|
||||
"description": "Sentientgeeks Boilerplate Node Express RESTApi ES2017",
|
||||
"author": "sentientgeeks",
|
||||
"main": "src/index.js",
|
||||
"engines": {
|
||||
"node": ">=8",
|
||||
"yarn": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"precommit": "yarn lint",
|
||||
"prestart": "yarn docs",
|
||||
"start:dev": "dotenv -v NODE_ENV=development -- nodemon ./src/index.js",
|
||||
"start": "node src/index.js",
|
||||
"start:local": "dotenv -v NODE_ENV=local -- nodemon ./src/index.js",
|
||||
"start:dev": "dotenv -v NODE_ENV=development -- node ./src/index.js",
|
||||
"start:prod": "dotenv -v NODE_ENV=production -- pm2 start ./src/index.js",
|
||||
"lint": "eslint ./src/ --ignore-path .gitignore --ignore-pattern internals/scripts",
|
||||
"lint:fix": "npx eslint --fix",
|
||||
@ -28,7 +24,6 @@
|
||||
"deploy": "sh ./deploy.sh",
|
||||
"docs": "apidoc -i src -o docs",
|
||||
"postdocs": "open-cli docs/index.html",
|
||||
"docker:start": "cross-env NODE_ENV=production pm2-docker start ./src/index.js",
|
||||
"docker:prod": "docker-compose -f docker-compose.yml -f docker-compose.prod.yml up",
|
||||
"docker:dev": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml up",
|
||||
"docker:test": "docker-compose -f docker-compose.yml -f docker-compose.test.yml up --abort-on-container-exit"
|
||||
|
@ -1,51 +0,0 @@
|
||||
const Joi = require('joi');
|
||||
|
||||
module.exports = {
|
||||
// POST /v1/auth/register
|
||||
register: {
|
||||
body: Joi.object({
|
||||
email: Joi.string().email().required(),
|
||||
password: Joi.string().required().min(6).max(128),
|
||||
}),
|
||||
},
|
||||
|
||||
// POST /v1/auth/login
|
||||
login: {
|
||||
body: Joi.object({
|
||||
email: Joi.string().email().required(),
|
||||
password: Joi.string().required().max(128),
|
||||
}),
|
||||
},
|
||||
|
||||
// POST /v1/auth/facebook
|
||||
// POST /v1/auth/google
|
||||
oAuth: {
|
||||
body: Joi.object({
|
||||
access_token: Joi.string().required(),
|
||||
}),
|
||||
},
|
||||
|
||||
// POST /v1/auth/refresh
|
||||
refresh: {
|
||||
body: Joi.object({
|
||||
email: Joi.string().email().required(),
|
||||
refreshToken: Joi.string().required(),
|
||||
}),
|
||||
},
|
||||
|
||||
// POST /v1/auth/refresh
|
||||
sendPasswordReset: {
|
||||
body: Joi.object({
|
||||
email: Joi.string().email().required(),
|
||||
}),
|
||||
},
|
||||
|
||||
// POST /v1/auth/password-reset
|
||||
passwordReset: {
|
||||
body: Joi.object({
|
||||
email: Joi.string().email().required(),
|
||||
password: Joi.string().required().min(6).max(128),
|
||||
resetToken: Joi.string().required(),
|
||||
}),
|
||||
},
|
||||
};
|
@ -44,15 +44,15 @@ passport.use('facebook', strategies.facebook);
|
||||
passport.use('google', strategies.google);
|
||||
|
||||
// mount api v1 routes
|
||||
app.use('/v1', routes);
|
||||
// app.use('/v1', routes);
|
||||
|
||||
// if error is not an instanceOf APIError, convert it.
|
||||
app.use(error.converter);
|
||||
// // if error is not an instanceOf APIError, convert it.
|
||||
// app.use(error.converter);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(error.notFound);
|
||||
// // catch 404 and forward to error handler
|
||||
// app.use(error.notFound);
|
||||
|
||||
// error handler, send stacktrace only during development
|
||||
app.use(error.handler);
|
||||
// // error handler, send stacktrace only during development
|
||||
// app.use(error.handler);
|
||||
|
||||
module.exports = app;
|
@ -26,7 +26,7 @@ exports.connect = () => {
|
||||
mongoose
|
||||
.connect(mongo.uri, {
|
||||
//useCreateIndex: true,
|
||||
keepAlive: 1,
|
||||
// keepAlive: 1,
|
||||
//useNewUrlParser: true,
|
||||
//useUnifiedTopology: true,
|
||||
//useFindAndModify: false,
|
@ -12,10 +12,7 @@ module.exports = {
|
||||
jwtSecret: process.env.JWT_SECRET,
|
||||
jwtExpirationInterval: process.env.JWT_EXPIRATION_MINUTES,
|
||||
mongo: {
|
||||
uri:
|
||||
process.env.NODE_ENV === 'test'
|
||||
? process.env.MONGO_URI_TESTS
|
||||
: process.env.MONGO_URI,
|
||||
uri: process.env.MONGO_URI,
|
||||
},
|
||||
logs: process.env.NODE_ENV === 'production' ? 'combined' : 'dev',
|
||||
emailConfig: {
|
@ -1,6 +1,6 @@
|
||||
const httpStatus = require('http-status');
|
||||
const { omit } = require('lodash');
|
||||
const User = require('../models/user.model');
|
||||
const User = require('../api/models/user.model');
|
||||
|
||||
/**
|
||||
* Load user and append to req.
|
@ -1,7 +1,7 @@
|
||||
const httpStatus = require('http-status');
|
||||
const expressValidation = require('express-validation');
|
||||
const APIError = require('../utils/APIError');
|
||||
const { env } = require('../../config/vars');
|
||||
const APIError = require('../api/utils/APIError');
|
||||
const { env } = require('../config/vars');
|
||||
|
||||
/**
|
||||
* Error handler. Send stacktrace only during development
|
@ -4,7 +4,7 @@ const { omitBy, isNil } = require('lodash');
|
||||
const bcrypt = require('bcryptjs');
|
||||
const moment = require('moment-timezone');
|
||||
const jwt = require('jwt-simple');
|
||||
const uuidv4 = require('uuid/v4');
|
||||
// const uuidv4 = require('uuid/v4');
|
||||
const APIError = require('../utils/APIError');
|
||||
const { env, jwtSecret, jwtExpirationInterval } = require('../../config/vars');
|
||||
|
@ -12,9 +12,9 @@ router.get('/status', (req, res) => res.send('OK'));
|
||||
/**
|
||||
* GET v1/docs
|
||||
*/
|
||||
router.use('/docs', express.static('docs'));
|
||||
// router.use('/docs', express.static('docs'));
|
||||
|
||||
router.use('/users', userRoutes);
|
||||
// router.use('/users', userRoutes);
|
||||
router.use('/auth', authRoutes);
|
||||
|
||||
module.exports = router;
|
@ -1,13 +1,13 @@
|
||||
const express = require('express');
|
||||
const { validate, ValidationError, Joi } = require('express-validation');
|
||||
const controller = require('../../controllers/user.controller');
|
||||
const { authorize, ADMIN, LOGGED_USER } = require('../../middlewares/auth');
|
||||
const controller = require('../../../controllers/user.controller');
|
||||
const { authorize, ADMIN, LOGGED_USER } = require('../../../middlewares/auth');
|
||||
const {
|
||||
listUsers,
|
||||
createUser,
|
||||
replaceUser,
|
||||
updateUser,
|
||||
} = require('../../validations/user.validation');
|
||||
} = require('../../../validations/user.validation');
|
||||
|
||||
const router = express.Router();
|
||||
|
@ -1,5 +1,5 @@
|
||||
const nodemailer = require('nodemailer');
|
||||
const { emailConfig } = require('../../../config/vars');
|
||||
const { emailConfig } = require('../../config/vars');
|
||||
const Email = require('email-templates');
|
||||
|
||||
// SMTP is the main transport in Nodemailer for delivering messages.
|
0
src/api/services/emails/passwordChange/subject.pug → src/services/emails/passwordChange/subject.pug
0
src/api/services/emails/passwordChange/subject.pug → src/services/emails/passwordChange/subject.pug
@ -6,9 +6,9 @@ const { expect } = require('chai');
|
||||
const sinon = require('sinon');
|
||||
const bcrypt = require('bcryptjs');
|
||||
const { some, omitBy, isNil } = require('lodash');
|
||||
const app = require('../../../index');
|
||||
const app = require('../../index');
|
||||
const User = require('../../models/user.model');
|
||||
const JWT_EXPIRATION = require('../../../config/vars').jwtExpirationInterval;
|
||||
const JWT_EXPIRATION = require('../../config/vars').jwtExpirationInterval;
|
||||
|
||||
/**
|
||||
* root level hooks
|
@ -1,5 +1,5 @@
|
||||
const Joi = require('joi');
|
||||
const User = require('../models/user.model');
|
||||
const User = require('../api/models/user.model');
|
||||
|
||||
module.exports = {
|
||||
// GET /v1/users
|
Loading…
x
Reference in New Issue
Block a user