├── data ├── bin │ └── files │ │ ├── diagram1.png │ │ ├── diagram2.png │ │ ├── diagram3.png │ │ ├── document1.png │ │ ├── document2.png │ │ ├── document3.png │ │ ├── document4.png │ │ └── document5.png └── api │ └── files │ ├── 2bc3994a98b.json │ └── index.json ├── Dockerfile ├── README.md └── nginx.conf /data/bin/files/diagram1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/accodeing/REST-API-mock/HEAD/data/bin/files/diagram1.png -------------------------------------------------------------------------------- /data/bin/files/diagram2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/accodeing/REST-API-mock/HEAD/data/bin/files/diagram2.png -------------------------------------------------------------------------------- /data/bin/files/diagram3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/accodeing/REST-API-mock/HEAD/data/bin/files/diagram3.png -------------------------------------------------------------------------------- /data/bin/files/document1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/accodeing/REST-API-mock/HEAD/data/bin/files/document1.png -------------------------------------------------------------------------------- /data/bin/files/document2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/accodeing/REST-API-mock/HEAD/data/bin/files/document2.png -------------------------------------------------------------------------------- /data/bin/files/document3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/accodeing/REST-API-mock/HEAD/data/bin/files/document3.png -------------------------------------------------------------------------------- /data/bin/files/document4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/accodeing/REST-API-mock/HEAD/data/bin/files/document4.png -------------------------------------------------------------------------------- /data/bin/files/document5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/accodeing/REST-API-mock/HEAD/data/bin/files/document5.png -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:1.13.12-alpine 2 | COPY nginx.conf /etc/nginx/nginx.conf 3 | #COPY data /usr/share/nginx/html 4 | EXPOSE 8080 5 | -------------------------------------------------------------------------------- /data/api/files/2bc3994a98b.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "2bc3994a98b", 3 | "name": "test.pdf", 4 | "date": "2018-04-25", 5 | "extra_attribute": 1234, 6 | "url": "/bin/files/2bc3994a98b.png" 7 | } 8 | -------------------------------------------------------------------------------- /data/api/files/index.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "53ba16558e38", 4 | "name": "overview.pdf", 5 | "url": "/bin/files/diagram1.png", 6 | "date": "2018-04-25" 7 | }, 8 | { 9 | "id": "5b656e16bf69", 10 | "name": "Sammanfattning av kvartalet Q3 2017.pdf", 11 | "url": "/bin/files/document1.png", 12 | "date": "2018-04-21" 13 | }, 14 | { 15 | "id": "5f752fd64ee2", 16 | "name": "Krav inför sprint 5.docx", 17 | "url": "/bin/files/document2.png", 18 | "date": "2018-04-17" 19 | }, 20 | { 21 | "id": "a7c4efe9c8b1", 22 | "name": "Utvärdering av sprint 4.rtf", 23 | "url": "/bin/files/document3.png", 24 | "date": "2018-04-16" 25 | }, 26 | { 27 | "id": "3f17d7285078", 28 | "name": "Relations diagram - API v1.0.png", 29 | "url": "/bin/files/diagram2.png", 30 | "date": "2018-04-16" 31 | }, 32 | { 33 | "id": "1329b610a5c6", 34 | "name": "Call graphs.pdf", 35 | "url": "/bin/files/diagram3.png", 36 | "date": "2018-03-29" 37 | }, 38 | { 39 | "id": "cb1bf43db0d5", 40 | "name": "Krav inför sprint 4.docx", 41 | "url": "/bin/files/document4.png", 42 | "date": "2018-03-22" 43 | }, 44 | { 45 | "id": "ebdc153dc9f5", 46 | "name": "Utvärdering av sprint 3.rtf", 47 | "url": "/bin/files/document5.png", 48 | "date": "2018-03-21" 49 | }, 50 | { 51 | "id": "53bb822fc868", 52 | "name": "demo.flv", 53 | "date": "2018-03-02" 54 | } 55 | ] 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Building 2 | 3 | Run `docker build -t faker .` in the same directory where you find the `Dockerfile` and `nginx.conf`. 4 | 5 | # Running 6 | 7 | Given a directory structure like: 8 | 9 | ``` 10 | ./ 11 | Dockerfile 12 | nginx.conf 13 | /data 14 | /api 15 | /files 16 | 2bc3994a98b.json 17 | index.json 18 | /bin 19 | /files 20 | 2bc3994a98b.png 21 | ``` 22 | 23 | To start the server and use the data directory for the API just run: 24 | 25 | ``` 26 | docker 27 | run 28 | --name faker 29 | -p 8080:8080 30 | --mount type=bind,source="$(pwd)"/data,target=/usr/share/nginx/html 31 | -it 32 | faker 33 | ``` 34 | 35 | Run `docker rm faker` if you get an error about the container name already being in use. 36 | 37 | # Extending 38 | 39 | If you want to bake the data into the image you need to edit the `Dockerfile` and uncomment/edit the line: `COPY data /usr/share/nginx/html` to match what directory you want to add. 40 | 41 | The added data should result in two directories, `/usr/share/nginx/html/api` and `/usr/share/nginx/html/bin`, being added to the image. 42 | 43 | Anything under `/api` should be folders with `index.json` and `[id].json` files to be served for requests like: `http://localhost/api/files` (`/api/files/index.json`) or `http://localhost/api/files/[id]` (`/api/files/[id].json`). These will all be served with a mime type of `application/json`. 44 | 45 | Under `/bin` everything will be served with a default mime type of `application/octet-stream` or a compatible binary mime type appropriate for the file. The structure here is up to you, it is just for serving static files. 46 | -------------------------------------------------------------------------------- /nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes 4; 2 | 3 | events { } 4 | 5 | http { 6 | 7 | types { 8 | text/html html htm shtml; 9 | text/css css; 10 | text/xml xml rss; 11 | image/gif gif; 12 | image/jpeg jpeg jpg; 13 | application/x-javascript js; 14 | text/plain txt; 15 | text/x-component htc; 16 | text/mathml mml; 17 | image/png png; 18 | image/x-icon ico; 19 | image/x-jng jng; 20 | image/vnd.wap.wbmp wbmp; 21 | application/java-archive jar war ear; 22 | application/mac-binhex40 hqx; 23 | application/pdf pdf; 24 | application/x-cocoa cco; 25 | application/x-java-archive-diff jardiff; 26 | application/x-java-jnlp-file jnlp; 27 | application/x-makeself run; 28 | application/x-perl pl pm; 29 | application/x-pilot prc pdb; 30 | application/x-rar-compressed rar; 31 | application/x-redhat-package-manager rpm; 32 | application/x-sea sea; 33 | application/x-shockwave-flash swf; 34 | application/x-stuffit sit; 35 | application/x-tcl tcl tk; 36 | application/x-x509-ca-cert der pem crt; 37 | application/x-xpinstall xpi; 38 | application/zip zip; 39 | application/octet-stream deb; 40 | application/octet-stream bin exe dll; 41 | application/octet-stream dmg; 42 | application/octet-stream eot; 43 | application/octet-stream iso img; 44 | application/octet-stream msi msp msm; 45 | audio/mpeg mp3; 46 | audio/x-realaudio ra; 47 | video/mpeg mpeg mpg; 48 | video/quicktime mov; 49 | video/x-flv flv; 50 | video/x-msvideo avi; 51 | video/x-ms-wmv wmv; 52 | video/x-ms-asf asx asf; 53 | video/x-mng mng; 54 | } 55 | 56 | log_format detailed '$remote_addr - $remote_user [$time_local] ' 57 | '"$request" $status $body_bytes_sent ' 58 | 'Referer: "$http_referer" - User agent: "$http_user_agent"' 59 | 'Authorization: "$http_authorization"'; 60 | 61 | error_log /dev/stdout debug; 62 | access_log /dev/stdout detailed; 63 | 64 | sendfile on; 65 | tcp_nopush on; 66 | 67 | server { 68 | listen 8080; 69 | real_ip_header X-Real-IP; 70 | set_real_ip_from 127.0.0.1; 71 | root /usr/share/nginx/html; 72 | 73 | location /bin/ { 74 | default_type 'application/octet-stream'; 75 | add_header 'Access-Control-Allow-Origin' '*' always; 76 | add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; 77 | 78 | try_files $uri =404; 79 | } 80 | 81 | location /api/ { 82 | if ($request_method = 'OPTIONS') { 83 | add_header 'Access-Control-Allow-Origin' '*'; 84 | add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; 85 | add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; 86 | add_header 'Access-Control-Max-Age' 1728000; 87 | add_header 'Content-Type' 'text/plain; charset=utf-8'; 88 | add_header 'Content-Length' 0; 89 | return 204; 90 | } 91 | default_type 'application/json'; 92 | add_header 'Access-Control-Allow-Origin' '*' always; 93 | add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; 94 | 95 | try_files $uri/index.json $uri.json $uri =404; 96 | } 97 | } 98 | } 99 | --------------------------------------------------------------------------------