Skip to content

Commit f03ffc8

Browse files
committed
Merge branch 'release/3.0.3'
2 parents ec97b7f + 0fd3811 commit f03ffc8

22 files changed

Lines changed: 258 additions & 211 deletions

CHANGELOG.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [3.0.3] - 2021-01-24
8+
9+
### Added
10+
11+
- Missing breaking change notice in the changelog of version 3.0.0 for those using a wildcard `Access-Control-Allow-Origin` header
12+
13+
### Fixed
14+
15+
- Unknown sizes id when a size is zero (#217)
16+
- Prevent unknown id errors like in #217 for other record properties
17+
- Updated ackee-tracker which re-added `ignoreOwnVisits` for those using a wildcard `Access-Control-Allow-Origin` header
18+
719
## [3.0.2] - 2021-01-21
820

921
### Fixed
@@ -43,6 +55,14 @@ Oh, and we also reduced the JS file size of the UI by ~60%.
4355

4456
### Breaking changes
4557

58+
#### `Access-Control-Allow-Origin: "*"` not recommended
59+
60+
> This change is relevant for you when using a wildcard as the Access-Control-Allow-Origin.
61+
62+
Using a wildcard (`*`) for the `Access-Control-Allow-Origin` header was never recommended as it's neither a secure solution nor does it allow Ackee to ignore your own visits. Please disable the `ignoreOwnVisits` option in ackee-tracker if you're currently using a wildcard. The [SSL and HTTPS](docs/SSL%20and%20HTTPS.md) guide contains better alternatives.
63+
64+
`ignoreOwnVisits` is now enabled by default and won't work when using a wildcard.
65+
4666
#### New `Access-Control-Allow-Credentials` header
4767

4868
> This change is relevant for everyone.
@@ -273,7 +293,7 @@ The first major back-end and front-end rewrite of Ackee with new API, dashboard,
273293
### Added
274294

275295
- Simply [deploy to Heroku](docs/Get%20started.md#with-heroku) by clicking one button (#72, thanks @aleccool213)
276-
- `ACKEE_ALLOW_ORIGIN` option for [Heroku or other Platforms-As-A-Service](docs/CORS%20headers.md) (#73, thanks @aleccool213)
296+
- `ACKEE_ALLOW_ORIGIN` option for [Platforms-As-A-Service](docs/CORS%20headers.md) (#73, thanks @aleccool213)
277297

278298
## [1.4.2] - 2019-12-19
279299

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tracker.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/CORS headers.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Ackee requires correct [CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). [ackee-tracker](https://github.com/electerious/ackee-tracker) (the script that sends data from your sites to Ackee) won't be able to contact your server when the CORS headers aren't available or when they are configured incorrectly.
44

55
- [Reverse proxy configuration](#reverse-proxy-configuration)
6-
- [Heroku or Platforms-As-A-Service configuration](#heroku-or-platforms-as-a-service-configuration)
6+
- [Platforms-As-A-Service configuration](#platforms-as-a-service-configuration)
77

88
## Why?
99

@@ -20,18 +20,12 @@ Access-Control-Allow-Credentials: true
2020

2121
### Origin
2222

23-
Your server needs to allow requests from your sites (recommended) or from all sites (easier to implement, but insecure).
23+
The `Access-Control-Allow-Origin` header only allows one domain. A wildcard (`*`) isn't recommended as it's neither a secure solution nor does it allow Ackee to ignore your own visits. Take a look at our [recommended configuration](SSL%20and%20HTTPS.md#recommended-configuration) if you want to allow requests from multiple domains or disable the `ignoreOwnVisits` option in ackee-tracker if using a wildcard is the only option for you.
2424

2525
```
2626
Access-Control-Allow-Origin: https://example.com
2727
```
2828

29-
```
30-
Access-Control-Allow-Origin: *
31-
```
32-
33-
The `Access-Control-Allow-Origin` header only allows one domain or a wildcard (`*`). Take a look at our [advanced configuration](SSL%20and%20HTTPS.md#advanced-configuration) if you want to allow requests from multiple domains without using the insecure wildcard.
34-
3529
### Methods
3630

3731
[ackee-tracker](https://github.com/electerious/ackee-tracker) needs the permission to send GET, POST, PATCH and OPTIONS requests to the server.
@@ -58,7 +52,7 @@ The `Access-Control-Allow-Credentials` header tells the browser to include the `
5852
Access-Control-Allow-Credentials: true
5953
```
6054

61-
## Heroku or Platforms-As-A-Service configuration
55+
## Platforms-As-A-Service configuration
6256

6357
If you are running Ackee on a platform which handles SSL for you, you may want a quick solution for setting CORS headers instead of using a [reverse proxy](SSL%20and%20HTTPS.md).
6458

@@ -68,14 +62,14 @@ As an environment variable, you will need to set:
6862
ACKEE_ALLOW_ORIGIN="https://example.com"
6963
```
7064

71-
The proper header value for `Access-Control-Allow-Origin` will be set with the other headers being the recommended values.
72-
73-
It's also possible to allow requests from all domains (not recommended) or from multiple domains:
65+
*or*
7466

7567
```
76-
ACKEE_ALLOW_ORIGIN="*"
68+
ACKEE_ALLOW_ORIGIN="https://example.com,https://one.example.com,https://two.example.com"
7769
```
7870

71+
Setting a wildcard (`*`) is also supported, but not recommended. It's neither a secure solution nor does it allow Ackee to ignore your own visits. Please disable the `ignoreOwnVisits` option in ackee-tracker if using a wildcard is the only option for you.
72+
7973
```
80-
ACKEE_ALLOW_ORIGIN="https://example.com,https://example2.com"
74+
ACKEE_ALLOW_ORIGIN="*"
8175
```

docs/Get started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Ackee now runs on port `3000` and is only accessible from you local network. It'
179179

180180
- You need to have a MongoDB instance running (e.g. [MongoDB Atlas](https://www.mongodb.com/cloud/atlas))
181181
- Set a username and password to protect your interface
182-
- Ensure that you're using the correct CORS headers by setting [`ACKEE_ALLOW_ORIGIN`](CORS%20headers.md#heroku-or-platforms-as-a-service-configuration).
182+
- Ensure that you're using the correct CORS headers by setting [`ACKEE_ALLOW_ORIGIN`](CORS%20headers.md#platforms-as-a-service-configuration).
183183

184184
### 3. Updating Ackee
185185

@@ -214,7 +214,7 @@ Deploy to Heroku by clicking this button:
214214
### 2. Configure Ackee
215215

216216
- You need to have a MongoDB instance running, either hosting it yourself, using [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) or by using a (paid) add-on like [ObjectRocket MongoDB](https://elements.heroku.com/addons/ormongo). This is as simple as typing `heroku addons:create ormongo:2-wt --app <YOUR_APP_NAME>` using the CLI, or using the web dashboard; more details at the [official documentation](https://devcenter.heroku.com/articles/managing-add-ons). You'll need to provide connection details to Ackee dyno, either from the web dashboard or via command line, e.g. `heroku config:add "ACKEE_MONGODB=mongodb://<host>:<port>/<db>"`
217-
- Ensure that you're using the correct CORS headers by setting [`ACKEE_ALLOW_ORIGIN`](CORS%20headers.md#heroku-or-platforms-as-a-service-configuration).
217+
- Ensure that you're using the correct CORS headers by setting [`ACKEE_ALLOW_ORIGIN`](CORS%20headers.md#platforms-as-a-service-configuration).
218218

219219
### 3. Updating Ackee
220220

docs/Options.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ NODE_ENV=development
7474

7575
## CORS headers
7676

77-
Quick solution for setting [CORS headers](CORS%20headers.md) instead of using a [reverse proxy](SSL%20and%20HTTPS.md). This is helpful if you are running Ackee on a platform which handles SSL for you.
77+
Quick solution for setting [CORS headers](CORS%20headers.md) instead of using a [reverse proxy](SSL%20and%20HTTPS.md). This is helpful if you are running Ackee on a platform that handles SSL for you.
7878

7979
```
80-
ACKEE_ALLOW_ORIGIN="*"
80+
ACKEE_ALLOW_ORIGIN="https://example.com"
8181
```
8282

8383
*or*
8484

8585
```
86-
ACKEE_ALLOW_ORIGIN="https://example.com"
86+
ACKEE_ALLOW_ORIGIN="https://example.com,https://one.example.com,https://two.example.com"
8787
```
8888

89-
*or*
89+
Setting a wildcard (`*`) is also supported, but not recommended. It's neither a secure solution nor does it allow Ackee to ignore your own visits. Please disable the `ignoreOwnVisits` option in ackee-tracker if using a wildcard is the only option for you.
9090

9191
```
92-
ACKEE_ALLOW_ORIGIN="https://example.com,https://example2.com"
92+
ACKEE_ALLOW_ORIGIN="*"
9393
```

docs/SSL and HTTPS.md

Lines changed: 75 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,15 @@ I highly recommend [this article](https://medium.com/intrinsic/why-should-i-use-
1414

1515
### nginx
1616

17-
#### Basic configuration
17+
- [Recommended configuration](#recommended-configuration)
18+
- [Single domain configuration](#single-domain-configuration)
19+
- [Insecure wildcard configuration](#insecure-wildcard-configuration)
1820

19-
This configuration secures all connections using TSL/SSL and gives any domain permission to access Ackee.
21+
#### Recommended configuration
2022

21-
> 👉 The CORS headers are required so all your sites can send data to Ackee, even when their domain is different to the one Ackee uses. Take a look at the next example to tighten the CORS headers.
23+
This configuration redirects all requests to the non-www domain `example.com`, secures connections using TSL/SSL and allows CORS requests from a list of known domains.
2224

23-
```conf
24-
server {
25-
listen 443 ssl http2;
26-
27-
server_name example.com;
28-
29-
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
30-
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
31-
32-
access_log /var/log/nginx/log/example.com.access.log main;
33-
error_log /var/log/nginx/log/example.com.error.log;
34-
35-
location / {
36-
add_header Access-Control-Allow-Origin "*" always;
37-
add_header Access-Control-Allow-Methods "GET, POST, PATCH, OPTIONS" always;
38-
add_header Access-Control-Allow-Headers "Content-Type, Authorization, Time-Zone" always;
39-
add_header Access-Control-Allow-Credentials "true" always;
40-
add_header Strict-Transport-Security "max-age=31536000" always;
41-
add_header X-Frame-Options deny;
42-
proxy_pass http://localhost:3000;
43-
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
44-
proxy_redirect off;
45-
proxy_buffering off;
46-
proxy_set_header Host $host;
47-
proxy_set_header X-Real-IP $remote_addr;
48-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
49-
}
50-
}
51-
```
52-
53-
#### Advanced configuration
54-
55-
This configuration redirects all requests to the non-www domain `example.com` and adds the CORS headers only for known domains. It also secures connections using TSL/SSL.
25+
> 👉 The CORS headers are required so your sites can send data to Ackee, even when their domain is different to the one Ackee uses.
5626
5727
```conf
5828
#
@@ -122,3 +92,72 @@ server {
12292
}
12393
}
12494
```
95+
96+
#### Single domain configuration
97+
98+
This configuration secures all connections using TSL/SSL and allows `https://example.com` to send data to `https://ackee.example.com`.
99+
100+
> ℹ️ This configuration only allows requests from a single domain. Take a look at our [recommended configuration](#recommended-configuration) if you want to allow requests from multiple domains or use the [insecure wildcard configuration](#insecure-wildcard-configuration).
101+
102+
```conf
103+
server {
104+
listen 443 ssl http2;
105+
106+
server_name ackee.example.com;
107+
108+
ssl_certificate /etc/letsencrypt/live/ackee.example.com/fullchain.pem;
109+
ssl_certificate_key /etc/letsencrypt/live/ackee.example.com/privkey.pem;
110+
111+
access_log /var/log/nginx/log/ackee.example.com.access.log main;
112+
error_log /var/log/nginx/log/ackee.example.com.error.log;
113+
114+
location / {
115+
add_header Access-Control-Allow-Origin "https://example.com" always;
116+
add_header Access-Control-Allow-Methods "GET, POST, PATCH, OPTIONS" always;
117+
add_header Access-Control-Allow-Headers "Content-Type, Authorization, Time-Zone" always;
118+
add_header Access-Control-Allow-Credentials "true" always;
119+
add_header Strict-Transport-Security "max-age=31536000" always;
120+
add_header X-Frame-Options deny;
121+
proxy_pass http://localhost:3000;
122+
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
123+
proxy_redirect off;
124+
proxy_buffering off;
125+
proxy_set_header Host $host;
126+
proxy_set_header X-Real-IP $remote_addr;
127+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
128+
}
129+
}
130+
```
131+
132+
#### Insecure wildcard configuration
133+
134+
A wildcard (`*`) isn't recommended as it's neither a secure solution nor does it allow Ackee to ignore your own visits. Please disable the `ignoreOwnVisits` option in ackee-tracker if using a wildcard is the only option for you.
135+
136+
```conf
137+
server {
138+
listen 443 ssl http2;
139+
140+
server_name ackee.example.com;
141+
142+
ssl_certificate /etc/letsencrypt/live/ackee.example.com/fullchain.pem;
143+
ssl_certificate_key /etc/letsencrypt/live/ackee.example.com/privkey.pem;
144+
145+
access_log /var/log/nginx/log/ackee.example.com.access.log main;
146+
error_log /var/log/nginx/log/ackee.example.com.error.log;
147+
148+
location / {
149+
add_header Access-Control-Allow-Origin "*" always;
150+
add_header Access-Control-Allow-Methods "GET, POST, PATCH, OPTIONS" always;
151+
add_header Access-Control-Allow-Headers "Content-Type, Authorization, Time-Zone" always;
152+
add_header Strict-Transport-Security "max-age=31536000" always;
153+
add_header X-Frame-Options deny;
154+
proxy_pass http://localhost:3000;
155+
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
156+
proxy_redirect off;
157+
proxy_buffering off;
158+
proxy_set_header Host $host;
159+
proxy_set_header X-Real-IP $remote_addr;
160+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
161+
}
162+
}
163+
```

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ackee",
33
"private": true,
4-
"version": "3.0.2",
4+
"version": "3.0.3",
55
"authors": [
66
"Tobias Reich <tobias@electerious.com>"
77
],
@@ -33,7 +33,7 @@
3333
"lint": "eslint '{functions,src,test}/**/*.js'"
3434
},
3535
"dependencies": {
36-
"ackee-tracker": "^5.0.0",
36+
"ackee-tracker": "^5.0.1",
3737
"apollo-server-lambda": "^2.19.2",
3838
"apollo-server-micro": "^2.19.2",
3939
"apollo-server-plugin-http-headers": "^0.1.4",
@@ -47,7 +47,7 @@
4747
"is-url": "^1.2.4",
4848
"micro": "^9.3.4",
4949
"microrouter": "^3.1.3",
50-
"mongoose": "^5.11.12",
50+
"mongoose": "^5.11.13",
5151
"node-fetch": "^2.6.1",
5252
"node-schedule": "^1.3.2",
5353
"normalize-url": "^5.0.0",

src/database/actions.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ const update = async (id, data) => {
5858

5959
const getChart = async (ids, type, interval, limit, dateDetails) => {
6060

61+
const aggregation = (() => {
62+
63+
if (type === 'TOTAL') return aggregateActions(ids, false, interval, limit, dateDetails)
64+
if (type === 'AVERAGE') return aggregateActions(ids, true, interval, limit, dateDetails)
65+
66+
})()
67+
6168
const enhance = (entries) => {
6269

6370
const matchDay = [ intervals.INTERVALS_DAILY ].includes(interval)
@@ -92,13 +99,6 @@ const getChart = async (ids, type, interval, limit, dateDetails) => {
9299

93100
}
94101

95-
const aggregation = (() => {
96-
97-
if (type === 'TOTAL') return aggregateActions(ids, false, interval, limit, dateDetails)
98-
if (type === 'AVERAGE') return aggregateActions(ids, true, interval, limit, dateDetails)
99-
100-
})()
101-
102102
return enhance(
103103
await Action.aggregate(aggregation)
104104
)

src/database/browsers.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,9 @@ const aggregateNewRecords = require('../aggregations/aggregateNewRecords')
66
const aggregateRecentRecords = require('../aggregations/aggregateRecentRecords')
77
const sortings = require('../constants/sortings')
88
const constants = require('../constants/browsers')
9-
const bestMatch = require('../utils/bestMatch')
109

1110
const get = async (ids, sorting, type, range, limit, dateDetails) => {
1211

13-
const enhance = (entries) => {
14-
15-
return entries.map((entry) => ({
16-
id: bestMatch([
17-
[ `${ entry._id.browserName } ${ entry._id.browserVersion }`, [ entry._id.browserName, entry._id.browserVersion ]],
18-
[ `${ entry._id.browserName }`, [ entry._id.browserName ]]
19-
]),
20-
count: entry.count,
21-
created: entry.created
22-
}))
23-
24-
}
25-
2612
const aggregation = (() => {
2713

2814
if (type === constants.BROWSERS_TYPE_NO_VERSION) {
@@ -38,6 +24,23 @@ const get = async (ids, sorting, type, range, limit, dateDetails) => {
3824

3925
})()
4026

27+
const enhanceId = (id) => {
28+
29+
if (type === constants.BROWSERS_TYPE_NO_VERSION) return `${ id.browserName }`
30+
if (type === constants.BROWSERS_TYPE_WITH_VERSION) return `${ id.browserName } ${ id.browserVersion }`
31+
32+
}
33+
34+
const enhance = (entries) => {
35+
36+
return entries.map((entry) => ({
37+
id: enhanceId(entry._id),
38+
count: entry.count,
39+
created: entry.created
40+
}))
41+
42+
}
43+
4144
return enhance(
4245
await Record.aggregate(aggregation)
4346
)

0 commit comments

Comments
 (0)