Skip to content

Commit b4095e8

Browse files
authored
cors nginx (#69)
1 parent 457e3a3 commit b4095e8

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

cors/nginx/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM nginx
2+
COPY default.conf /etc/nginx/templates/default.conf.template

cors/nginx/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Testing
2+
3+
1. Deploy container
4+
5+
```sh
6+
docker compose up -d --build
7+
```
8+
9+
1. Open a website
10+
1. Open Developer console
11+
1. Run:
12+
13+
```js
14+
fetch('http://localhost:7100/about').then(res => res.json()).then(console.log).catch(console.error);
15+
```

cors/nginx/compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
nginx:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
ports:
7+
- "7100:7100"

cors/nginx/default.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
server {
2+
listen 7100;
3+
4+
add_header 'Access-Control-Allow-Origin' '*' always;
5+
6+
location /about {
7+
default_type application/json;
8+
return 200 '{"description":"nginx router","version":"1.0"}';
9+
}
10+
11+
error_page 404 @404_json;
12+
13+
location @404_json {
14+
default_type application/json;
15+
return 404 '{"statusCode":"NotFound","reason":"NoNginxRoute"}';
16+
}
17+
}

0 commit comments

Comments
 (0)