Skip to content

Commit

Permalink
Version info added to url
Browse files Browse the repository at this point in the history
  • Loading branch information
Melih Korkmaz committed Jun 6, 2018
1 parent 3bd8ae5 commit 45b9d7a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -18,7 +18,7 @@
"rest",
"api"
],
"author": "",
"author": "Melih Korkmaz - melihkorkmaz84@gmail.com",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
Expand Down
4 changes: 3 additions & 1 deletion src/config.js
@@ -1,4 +1,6 @@
module.exports = {
maxDataItem : 100,
connectionString : ""
connectionString : "",
port : 8080,
apiVersion : "v1"
}
3 changes: 2 additions & 1 deletion src/index.js
Expand Up @@ -3,6 +3,7 @@ import morgan from 'morgan';
import bodyParser from 'body-parser';
import routes from './routes';
import mongo from './utils/mongo.helper';
import config from './config';
import loggerMiddleware from './utils/logger.middleware';

const app = express();
Expand All @@ -28,5 +29,5 @@ routes(app);
if (NODE_ENV === 'test') {
module.exports = app;
} else {
app.listen(process.env.PORT || 8080, () => console.log('Server has been started'));
app.listen(process.env.PORT || config.port, () => console.log('Server has been started'));
}
9 changes: 5 additions & 4 deletions src/routes/index.js
@@ -1,12 +1,13 @@
import config from '../config';
import cityRoutes from './city.routes';
import townRoutes from './town.routes';
import districtRoutes from './district.routes';
import neightborhoodsRoutes from './neighborhoods.routes';


module.exports = (app) => {
app.use('/cities', cityRoutes);
app.use('/towns', townRoutes);
app.use('/districts', districtRoutes);
app.use('/neighborhoods', neightborhoodsRoutes);
app.use(`/${config.apiVersion}/cities`, cityRoutes);
app.use(`/${config.apiVersion}/towns`, townRoutes);
app.use(`/${config.apiVersion}/districts`, districtRoutes);
app.use(`/${config.apiVersion}/neighborhoods`, neightborhoodsRoutes);
};
12 changes: 6 additions & 6 deletions test/routes/city.routes.spec.js
Expand Up @@ -18,7 +18,7 @@ describe('Cities routes', () => {
describe('/cities', () => {
it('should return top 100 cities as default', done => {
chai.request(server)
.get('/cities')
.get(`/${config.apiVersion}/cities`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand All @@ -37,7 +37,7 @@ describe('Cities routes', () => {

it('should return limited cities data', done => {
chai.request(server)
.get('/cities?limit=10')
.get(`/${config.apiVersion}/cities?limit=10`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand All @@ -55,7 +55,7 @@ describe('Cities routes', () => {

it('should return towns if requested', done => {
chai.request(server)
.get('/cities?fields=towns,name')
.get(`/${config.apiVersion}/cities?fields=towns,name`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand All @@ -82,7 +82,7 @@ describe('Cities routes', () => {
describe('/cities/:id', done => {
it('should return city without towns', (done) => {
chai.request(server)
.get('/cities/fbf55ec2f75ae0ee54a2c55b49eef828')
.get(`/${config.apiVersion}/cities/fbf55ec2f75ae0ee54a2c55b49eef828`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('object');
Expand All @@ -95,7 +95,7 @@ describe('Cities routes', () => {
})
it('should return city towns if requested', (done) => {
chai.request(server)
.get('/cities/fbf55ec2f75ae0ee54a2c55b49eef828?fields=name,towns')
.get(`/${config.apiVersion}/cities/fbf55ec2f75ae0ee54a2c55b49eef828?fields=name,towns`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('object');
Expand All @@ -115,7 +115,7 @@ describe('Cities routes', () => {
describe('/cities/:id/towns', done => {
it('should return town list with default fields', (done) => {
chai.request(server)
.get('/cities/fbf55ec2f75ae0ee54a2c55b49eef828/towns')
.get(`/${config.apiVersion}/cities/fbf55ec2f75ae0ee54a2c55b49eef828/towns`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand Down
12 changes: 6 additions & 6 deletions test/routes/district.routes.spec.js
Expand Up @@ -16,7 +16,7 @@ describe('Districts routes', () => {
describe('/districts', () => {
it('should return top 100 districts as default', done => {
chai.request(server)
.get('/districts')
.get(`/${config.apiVersion}/districts`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand All @@ -36,7 +36,7 @@ describe('Districts routes', () => {

it('should return limited districts data', done => {
chai.request(server)
.get('/districts?limit=10')
.get(`/${config.apiVersion}/districts?limit=10`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand All @@ -55,7 +55,7 @@ describe('Districts routes', () => {

it('should return neighborhoods if requested', done => {
chai.request(server)
.get('/districts?fields=neighborhoods,name')
.get(`/${config.apiVersion}/districts?fields=neighborhoods,name`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('Districts routes', () => {
describe('/districts/:id', done => {
it('should return districts without neighborhoods', (done) => {
chai.request(server)
.get('/districts/001d6df71fa45a535b31eef430977a2b')
.get(`/${config.apiVersion}/districts/001d6df71fa45a535b31eef430977a2b`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('object');
Expand All @@ -100,7 +100,7 @@ describe('Districts routes', () => {
})
it('should return districts with neighborhoods if requested', (done) => {
chai.request(server)
.get('/districts/001d6df71fa45a535b31eef430977a2b?fields=name,neighborhoods')
.get(`/${config.apiVersion}/districts/001d6df71fa45a535b31eef430977a2b?fields=name,neighborhoods`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('object');
Expand All @@ -121,7 +121,7 @@ describe('Districts routes', () => {
describe('/districts/:id/neighborhoods', done => {
it('should return neighborhoods list with default fields', (done) => {
chai.request(server)
.get('/districts/001d6df71fa45a535b31eef430977a2b/neighborhoods')
.get(`/${config.apiVersion}/districts/001d6df71fa45a535b31eef430977a2b/neighborhoods`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand Down
6 changes: 3 additions & 3 deletions test/routes/neighborhoods.routes.spec.js
Expand Up @@ -16,7 +16,7 @@ describe('Neighborhoods routes', () => {
describe('/neighborhoods', () => {
it('should return top 100 neighborhoods as default', done => {
chai.request(server)
.get('/neighborhoods')
.get(`/${config.apiVersion}/neighborhoods`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand All @@ -38,7 +38,7 @@ describe('Neighborhoods routes', () => {

it('should return limited neighborhoods data', done => {
chai.request(server)
.get('/neighborhoods?limit=10')
.get(`/${config.apiVersion}/neighborhoods?limit=10`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand All @@ -61,7 +61,7 @@ describe('Neighborhoods routes', () => {
describe('/neighborhoods/:id', done => {
it('should return neighborhoods with default fields', (done) => {
chai.request(server)
.get('/neighborhoods/00021ac2ce842415456ed4be91e1a9bf')
.get(`/${config.apiVersion}/neighborhoods/00021ac2ce842415456ed4be91e1a9bf`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('object');
Expand Down
14 changes: 7 additions & 7 deletions test/routes/town.routes.spec.js
Expand Up @@ -16,7 +16,7 @@ describe('Towns routes', () => {
describe('/towns', () => {
it('should return top 100 towns as default', done => {
chai.request(server)
.get('/towns')
.get(`/${config.apiVersion}/towns`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand All @@ -36,7 +36,7 @@ describe('Towns routes', () => {

it('should return limited towns data', done => {
chai.request(server)
.get('/towns?limit=10')
.get(`/${config.apiVersion}/towns?limit=10`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand All @@ -55,7 +55,7 @@ describe('Towns routes', () => {

it('should return districts if requested', done => {
chai.request(server)
.get('/towns?fields=districts,name')
.get(`/${config.apiVersion}/towns?fields=districts,name`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('Towns routes', () => {
describe('/towns/:id', () => {
it('should return towns without districts', (done) => {
chai.request(server)
.get('/towns/c75bb35b73183e1abf9f948b3949b0ae')
.get(`/${config.apiVersion}/towns/c75bb35b73183e1abf9f948b3949b0ae`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('object');
Expand All @@ -97,7 +97,7 @@ describe('Towns routes', () => {
})
it('should return city towns if requested', (done) => {
chai.request(server)
.get('/towns/c75bb35b73183e1abf9f948b3949b0ae?fields=name,districts')
.get(`/${config.apiVersion}/towns/c75bb35b73183e1abf9f948b3949b0ae?fields=name,districts`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('object');
Expand All @@ -118,7 +118,7 @@ describe('Towns routes', () => {
describe('/towns/:id/districts', () => {
it('should return districts list with default fields', (done) => {
chai.request(server)
.get('/towns/c75bb35b73183e1abf9f948b3949b0ae/districts')
.get(`/${config.apiVersion}/towns/c75bb35b73183e1abf9f948b3949b0ae/districts`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand All @@ -137,7 +137,7 @@ describe('Towns routes', () => {
describe('/towns/:id/neighborhoods', () => {
it('should return all neighborhoods for town', done =>{
chai.request(server)
.get('/towns/c75bb35b73183e1abf9f948b3949b0ae/neighborhoods')
.get(`/${config.apiVersion}/towns/c75bb35b73183e1abf9f948b3949b0ae/neighborhoods`)
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.data).to.be.a('array');
Expand Down

0 comments on commit 45b9d7a

Please sign in to comment.