Skip to content

Commit

Permalink
Merge branch 'v.0.13.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
zaibugemi committed Oct 5, 2022
2 parents d798abb + 5c9a26d commit b16748c
Show file tree
Hide file tree
Showing 94 changed files with 16,051 additions and 3,413 deletions.
33 changes: 31 additions & 2 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@
"avatar_url": "https://avatars.githubusercontent.com/u/69869135?v=4",
"profile": "https://github.com/devrrior",
"contributions": [
"doc"
"doc",
"test"
]
},
{
Expand All @@ -198,7 +199,35 @@
"contributions": [
"doc"
]
}
},
{
"login": "vaibhavg20comp",
"name": "Vaibhav Garje",
"avatar_url": "https://avatars.githubusercontent.com/u/96220995?v=4",
"profile": "https://github.com/vaibhavg20comp",
"contributions": [
"code",
"test"
]
},
{
"login": "fms12",
"name": "Mayank Singh",
"avatar_url": "https://avatars.githubusercontent.com/u/68012074?v=4",
"profile": "https://github.com/fms12",
"contributions": [
"doc"
]
},
{
"login": "computamike",
"name": "Mike Hingley",
"avatar_url": "https://avatars.githubusercontent.com/u/464876?v=4",
"profile": "https://github.com/computamike",
"contributions": [
"code"
]
},
],
"contributorsPerLine": 7,
"skipCi": true,
Expand Down
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SCHEME=http
HOSTNAME=localhost:3000
6 changes: 4 additions & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"singleQuote": true,
"arrowParens": "always",
"printWidth": 120,
"semi": true
}
"semi": true,
"tabWidth": 4,
"useTabs": false
}
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:12-alpine
WORKDIR /src
COPY package.json package-lock.json /src/
RUN npm install
COPY . .
EXPOSE 3000
RUN npm config set unsafe-perm true
CMD ["npm", "run", "serve"]
44 changes: 40 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-21-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-23-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

<p align="center" style="margin-bottom: 20px">
Expand Down Expand Up @@ -36,9 +36,14 @@ First you should head over to https://api.mocked-api.dev and read our live api d
Once you've cloned this repository, running Mocked-API is quite easy, there are just 2 steps you have to follow:
1. Install the dependencies
```bash
npm run install
npm install
```
2. Serve the application
2. Configure the application
An example configuration file `.env.example` is provided.
```bash
npm run config
```
3. Serve the application
```bash
npm run serve
```
Expand All @@ -47,10 +52,36 @@ This will show you where the application is running
Mock API is running on port 3000.
```

## Getting Started (Docker)

1. Ensure you have Docker installed
1. Open your terminal/command line tool
1. Run `docker-compose up`
1. Open your browser to [http://localhost:3000/](http://localhost:3000/)

Now you should be able to make any request to that port, and get a response back!

💡 If you browse to that port, you'll see our swagger documentation.


## Testing

### How to write tests
For each module you create you will also need to create a tests folder, Inside this folder there should be a `api` and `utils`
(if you create any utils) folder.

The utils tests are fairly simple jests tests, the `api` routes tests are slightly different where you will need to add
```javascript
const request = require('supertest');
const baseURL = 'http://localhost:3000';
```
to your tests and make a request in your test instead of calling a normal function.

### How to run tests
1. Run the mocked api server locally
2. run `npm run test`


## FAQ

**Q:** Are you planning to add more end points? <br />
Expand Down Expand Up @@ -116,9 +147,14 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://derzan.dev/"><img src="https://avatars.githubusercontent.com/u/76019114?v=4?s=100" width="100px;" alt="Derzan Chiang"/><br /><sub><b>Derzan Chiang</b></sub></a><br /><a href="https://github.com/ageddesi/Mocked-API/commits?author=MiTo0o" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/ATH42"><img src="https://avatars.githubusercontent.com/u/80352300?v=4?s=100" width="100px;" alt="ATH"/><br /><sub><b>ATH</b></sub></a><br /><a href="https://github.com/ageddesi/Mocked-API/commits?author=ATH42" title="Documentation">📖</a></td>
<td align="center"><a href="http://suraj-bhandarkar-s.github.io/web/"><img src="https://avatars.githubusercontent.com/u/42907076?v=4?s=100" width="100px;" alt="Suraj Bhandarkar S"/><br /><sub><b>Suraj Bhandarkar S</b></sub></a><br /><a href="https://github.com/ageddesi/Mocked-API/commits?author=Suraj-Bhandarkar-S" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/devrrior"><img src="https://avatars.githubusercontent.com/u/69869135?v=4?s=100" width="100px;" alt="Fernando Guerrero"/><br /><sub><b>Fernando Guerrero</b></sub></a><br /><a href="https://github.com/ageddesi/Mocked-API/commits?author=devrrior" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/devrrior"><img src="https://avatars.githubusercontent.com/u/69869135?v=4?s=100" width="100px;" alt="Fernando Guerrero"/><br /><sub><b>Fernando Guerrero</b></sub></a><br /><a href="https://github.com/ageddesi/Mocked-API/commits?author=devrrior" title="Documentation">📖</a> <a href="https://github.com/ageddesi/Mocked-API/commits?author=devrrior" title="Tests">⚠️</a></td>
<td align="center"><a href="https://anishde.dev/"><img src="https://avatars.githubusercontent.com/u/63192115?v=4?s=100" width="100px;" alt="Anish De"/><br /><sub><b>Anish De</b></sub></a><br /><a href="https://github.com/ageddesi/Mocked-API/commits?author=AnishDe12020" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/vaibhavg20comp"><img src="https://avatars.githubusercontent.com/u/96220995?v=4?s=100" width="100px;" alt="Vaibhav Garje"/><br /><sub><b>Vaibhav Garje</b></sub></a><br /><a href="https://github.com/ageddesi/Mocked-API/commits?author=vaibhavg20comp" title="Code">💻</a> <a href="https://github.com/ageddesi/Mocked-API/commits?author=vaibhavg20comp" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/computamike"><img src="https://avatars.githubusercontent.com/u/464876?v=4?s=100" width="100px;" alt="Mike Hingley"/><br /><sub><b>Mike Hingley</b></sub></a><br /><a href="https://github.com/ageddesi/Mocked-API/commits?author=computamike" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/fms12"><img src="https://avatars.githubusercontent.com/u/68012074?v=4?s=100" width="100px;" alt="Mayank Singh"/><br /><sub><b>Mayank Singh</b></sub></a><br /><a href="https://github.com/ageddesi/Mocked-API/commits?author=fms12" title="Documentation">📖</a></td>
</tr>
</tbody>
<tfoot>

Expand Down
49 changes: 30 additions & 19 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
require('dotenv').config();
const express = require('express');
import express, { Request, Response } from 'express';
import { swaggerSpec } from './utils/swagger';

const morgan = require('morgan');
const cors = require('cors');

const app = express();
const port = 3000;

// Load Mock Modules
require('./modules/animal/api/animal-routes')(app) // Animals
require('./modules/chat/api/chat-routes')(app) // Chat
require('./modules/animal/api/animal-routes')(app); // Animals
require('./modules/chat/api/chat-routes')(app); // Chat
require('./modules/colors/api/colors-route')(app); // Colors
require('./modules/countries/api/countries-routes')(app); // Countries
require('./modules/currency/api/currency-routes')(app); // Currencies
require('./modules/ecommerce/api/ecommerce-routes')(app); // Ecommerce
require('./modules/emails/api/emails-routes')(app); // Emails
require('./modules/images/api/images-routes')(app); // Images
require('./modules/names/api/names-routes')(app); // Names
Expand All @@ -20,31 +23,39 @@ require('./modules/socials/api/socials-routes')(app); // Socials
require('./modules/sports/api/sports-routes')(app); // Sports
require('./modules/users/api/user-routes')(app); //Users
require('./modules/music/api/music-routes')(app); // Music
require('./modules/quotes/api/qoutes-routes')(app); // Quotes
require('./modules/invoice/api/invoice-routes')(app); // Invoices
require('./modules/elements/api/elements-routes')(app); // Chemical Elements
require('./modules/time_zones/api/timezones-routes.ts')(app); // Timezones
require('./modules/phone-numbers/api/phone-numbers-routes')(app); // Phone numbers
require('./modules/quotes/api/quotes-routes')(app); // Quotes
require('./modules/ip/api/ip-routes')(app); // ip and mac address
require('./modules/vehicles/api/vehicles-routes')(app); // Vehicles
require('./modules/address/api/address-routes')(app); // Addresses

// Add an healthcheck endpoint
app.get('/status', (req, res) => {
const data = {
uptime: process.uptime(),
message: 'Ok',
date: new Date()
}
res.status(200).send(data);
const data = {
uptime: process.uptime(),
message: 'Ok',
date: new Date(),
};
res.status(200).send(data);
});

// Docs in JSON format
app.get('/docs.json', (req: Request, res: Response) => {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});

// Setup Swagger API Documentation
const swaggerUi = require('swagger-ui-express')
const swaggerDocument = require('./swagger.json');
app.use(
'/',
swaggerUi.serve,
swaggerUi.setup(swaggerDocument)
);
const swaggerUi = require('swagger-ui-express');
app.use('/', swaggerUi.serve, swaggerUi.setup(swaggerSpec));


app.use(cors()); // enabling CORS for all requests
app.use(morgan('combined')); // adding morgan to log HTTP requests
app.use(morgan('combined')); // adding morgan to log HTTP requests

app.listen(port, () => {
console.log(`Mock API is running on port ${port}.`);
console.log(`Mock API is running on port ${port}.`);
});
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.7'

services:
mocked-api:
build:
dockerfile: Dockerfile
context: .
ports:
- 3000:3000
volumes:
- "./:/usr/src/app/"
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
}
Loading

0 comments on commit b16748c

Please sign in to comment.