This commit is contained in:
Mike Cao 2020-08-22 19:55:53 -07:00
commit fa20f7f67f
9 changed files with 67 additions and 24 deletions

6
.dockerignore Normal file
View File

@ -0,0 +1,6 @@
.git
docker-compose.yml
Dockerfile
.gitignore
.DS_Store
node_modules

View File

@ -1,5 +1,10 @@
FROM node:12.18-alpine FROM node:12.18-alpine
ARG DATABASE_TYPE
ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami" \
DATABASE_TYPE=$DATABASE_TYPE
COPY . /app COPY . /app
WORKDIR /app WORKDIR /app

View File

@ -38,7 +38,7 @@ export default function ActiveUsers({ websiteId, className }) {
<animated.div className={styles.value}> <animated.div className={styles.value}>
{props.x.interpolate(x => x.toFixed(0))} {props.x.interpolate(x => x.toFixed(0))}
</animated.div> </animated.div>
<div>{`current vistor${count !== 1 ? 's' : ''}`}</div> <div>{`current visitor${count !== 1 ? 's' : ''}`}</div>
</div> </div>
</div> </div>
); );

View File

@ -1,25 +1,24 @@
version: '3.8' ---
version: '3'
services: services:
umami: umami:
build: . build: .
ports: ports:
- "3000:3000" - "3000:3000"
environment: environment:
DATABASE_URL: postgresql://umami:umami@postgres:5432/umami DATABASE_URL: postgresql://umami:umami@db:5432/umami
DATABASE_TYPE: postgresql
HASH_SALT: replace-me-with-a-random-string HASH_SALT: replace-me-with-a-random-string
postgres: depends_on:
- db
db:
image: postgres:alpine image: postgres:alpine
ports:
- "5432:5432"
environment: environment:
POSTGRES_DB: umami
POSTGRES_USER: umami POSTGRES_USER: umami
POSTGRES_PASSWORD: umami POSTGRES_PASSWORD: umami
volumes: volumes:
- type: bind - ./sql/schema.postgresql.sql:/docker-entrypoint-initdb.d/schema.postgresql.sql:ro
source: ./sql/schema.postgresql.sql - umami-db-data:/var/lib/postgresql/data
target: /docker-entrypoint-initdb.d/schema.postgresql.sql
- type: volume
source: postgres-data
target: /var/lib/postgresql/data
volumes: volumes:
postgres-data: umami-db-data:

View File

@ -46,3 +46,28 @@ export const hook = (_this, method, callback) => {
return orig.apply(_this, args); return orig.apply(_this, args);
}; };
}; };
export const doNotTrack = () => {
if (
window.doNotTrack ||
navigator.doNotTrack ||
navigator.msDoNotTrack ||
'msTrackingProtectionEnabled' in window.external
) {
if (
window.doNotTrack == '1' ||
navigator.doNotTrack == 'yes' ||
navigator.doNotTrack == '1' ||
navigator.msDoNotTrack == '1' ||
(window.external &&
window.external.msTrackingProtectionEnabled &&
window.external.msTrackingProtectionEnabled())
) {
return true;
} else {
return false;
}
} else {
return false;
}
};

View File

@ -6,6 +6,7 @@ import NotFound from 'pages/404';
import { get } from 'lib/web'; import { get } from 'lib/web';
export default function SharePage() { export default function SharePage() {
const [loading, setLoading] = useState(true);
const [websiteId, setWebsiteId] = useState(); const [websiteId, setWebsiteId] = useState();
const [notFound, setNotFound] = useState(false); const [notFound, setNotFound] = useState(false);
const router = useRouter(); const router = useRouter();
@ -23,10 +24,16 @@ export default function SharePage() {
useEffect(() => { useEffect(() => {
if (id) { if (id) {
loadData(); loadData().finally(() => {
setLoading(false);
});
} else {
setLoading(false);
} }
}, [id]); }, [id]);
if (loading) return null;
if (!id || notFound) { if (!id || notFound) {
return <NotFound />; return <NotFound />;
} }

File diff suppressed because one or more lines are too long

View File

@ -2,15 +2,15 @@ require('dotenv').config();
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const db = process.env.DATABASE_URL.split(':')[0]; const databaseType = process.env.DATABASE_TYPE || process.env.DATABASE_URL.split(':')[0];
if (!db) { if (!databaseType) {
throw new Error('Database not specified'); throw new Error('Database schema not specified');
} }
console.log(`Database detected: ${db}`); console.log(`Database schema detected: ${databaseType}`);
const src = path.resolve(__dirname, `../prisma/schema.${db}.prisma`); const src = path.resolve(__dirname, `../prisma/schema.${databaseType}.prisma`);
const dest = path.resolve(__dirname, '../prisma/schema.prisma'); const dest = path.resolve(__dirname, '../prisma/schema.prisma');
fs.copyFileSync(src, dest); fs.copyFileSync(src, dest);

View File

@ -1,6 +1,6 @@
import 'promise-polyfill/src/polyfill'; import 'promise-polyfill/src/polyfill';
import 'unfetch/polyfill'; import 'unfetch/polyfill';
import { post, hook } from '../lib/web'; import { post, hook, doNotTrack } from '../lib/web';
(window => { (window => {
const { const {
@ -13,7 +13,7 @@ import { post, hook } from '../lib/web';
const script = document.querySelector('script[data-website-id]'); const script = document.querySelector('script[data-website-id]');
if (!script) return; if (!script || doNotTrack()) return;
const website = script.getAttribute('data-website-id'); const website = script.getAttribute('data-website-id');
const hostUrl = new URL(script.src).origin; const hostUrl = new URL(script.src).origin;
@ -53,10 +53,11 @@ import { post, hook } from '../lib/web';
/* Handle history */ /* Handle history */
const handlePush = (state, title, url) => { const handlePush = (state, title, navaigatedUrl) => {
removeEvents(); removeEvents();
currentRef = currentUrl; currentRef = currentUrl;
currentUrl = url; const url = new URL(navaigatedUrl);
currentUrl = `${url.pathname}${url.search}`;
pageView(); pageView();
}; };