Skip to content

Commit

Permalink
Merge 43b449f into 6c70d9e
Browse files Browse the repository at this point in the history
  • Loading branch information
Alpha1202 committed Jul 12, 2019
2 parents 6c70d9e + 43b449f commit 01d1716
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/db/migrations/20190701154222-create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ module.exports = {
},
}),
down: (queryInterface) => queryInterface.dropTable('Users'),
};
};
32 changes: 32 additions & 0 deletions src/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,38 @@ router.post('/signup',

router.get('/verify/:token', AuthController.verifyAccount);
router.post('/login', emailValidator, passwordValidator, validate, AuthController.login);

/**
* @swagger
*
* /auth/google:
* get:
* tags:
* - auth
* description: Google Social Login
* produces:
* - application/json
* responses:
* 201:
* description: Success
*/
router.post('/login', AuthController.login);
router.post('/logout', ValidateToken.checkToken, AuthController.logOut);

/**
* @swagger
*
* /auth/google:
* post:
* tags:
* - auth
* description: Google Social Login
* produces:
* - application/json
* responses:
* 201:
* description: Success
*/
router.post('/logout', AuthController.logOut);

export default router;
25 changes: 3 additions & 22 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import bodyParser from 'body-parser';
import session from 'express-session';
import cors from 'cors';
import errorhandler from 'errorhandler';
import swaggerJSDoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';
import passport from 'passport';
import config from './db/config/config';
Expand All @@ -12,41 +11,23 @@ import triggerCronJob from './helpers/cronJobHelper';
import {
googleStrategy, facebookStrategy, twitterStrategy, gitHubStrategy, SerializeSetUp
} from './config/social_config';
import swaggerSpec from '../swagger';


const { isProduction, port } = config;
// Create global app object
const app = express();
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Authors Haven',
version: '1.0.0',
description: 'Endpoints for Authors Haven',
},
securityDefinitions: {
bearerAuth: {
type: 'apiKey',
name: 'Authorization',
scheme: 'bearer',
in: 'header',
},
},
},
apis: ['./routes/api/*.js'],
};
const swaggerSpec = swaggerJSDoc(options);

// It triggers the cron job
triggerCronJob();


app.get('/api-docs.json', (req, res) => {
app.get('/api/v1/doc', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});


app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));

app.use(cors());
Expand Down
30 changes: 30 additions & 0 deletions swagger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import swaggerJSDoc from 'swagger-jsdoc';


// swagger definition
const swaggerDefinition = {
info: {
title: 'Authors Haven Documentation',
version: '1.0.0',
description:
'Endpoints for Authors Haven',
},
host: 'localhost:3000',
basePath: '/api',
schemes: ['https', 'http'],
securityDefinitions: {
jwt: {
type: 'apiKey',
name: 'Authorization',
in: 'header',
},
},
security: [{ jwt: [] }],
};

// initialize swagger-jsdoc
const swaggerSpec = swaggerJSDoc({
swaggerDefinition,
apis: ['./src/routes/*.js', './src/ models/*.js'], // pass all in array
});
export default swaggerSpec;
7 changes: 3 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ describe('server', () => {
});
describe('Swagger', () => {
it('should return an object', (done) => {
chai.request(app).get('/api-docs.json')
chai.request(app).get('/api-docs')
.end((err, res) => {
expect(res.body).to.have.property('openapi');
expect(res.body).to.have.property('info');
expect(res.body).to.have.property('securityDefinitions');
res.should.have.status(200);
res.body.should.be.an('object');
done();
});
});
Expand Down

0 comments on commit 01d1716

Please sign in to comment.