Initial commit.

This commit is contained in:
Mike Cao 2020-07-17 01:03:38 -07:00
commit f7f0c05e12
27 changed files with 13028 additions and 0 deletions

10
pages/404.js Normal file
View file

@ -0,0 +1,10 @@
import React from 'react';
import Layout from 'components/layout';
export default function Custom404() {
return (
<Layout title="404 - Page Not Found">
<h1>oops</h1>
</Layout>
);
}

7
pages/_app.js Normal file
View file

@ -0,0 +1,7 @@
import React from 'react';
import 'styles/index.css';
import 'styles/bootstrap-grid.css';
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />;
}

16
pages/api/collect.js Normal file
View file

@ -0,0 +1,16 @@
import { parseCollectRequest } from 'lib/utils';
import { savePageView } from '../../lib/db';
export default async (req, res) => {
const values = parseCollectRequest(req);
if (values) {
const { type, session_id, url, referrer } = values;
if (type === 'pageview') {
await savePageView(session_id, url, referrer);
}
}
res.status(200).json({ status: 'ok' });
};

28
pages/api/session.js Normal file
View file

@ -0,0 +1,28 @@
import { getWebsite, getSession, createSession } from 'lib/db';
import { hash, parseSessionRequest } from 'lib/utils';
export default async (req, res) => {
let result = { time: Date.now() };
const { website_id, session_id, browser, os, screen, language, country } = parseSessionRequest(
req,
);
const website = await getWebsite(website_id);
if (website) {
const session = await getSession(session_id);
if (!session) {
await createSession(website_id, session_id, { browser, os, screen, language, country });
}
result = {
...result,
session_id,
website_id,
hash: hash(`${website_id}${session_id}${result.time}`),
};
}
res.status(200).json(result);
};

10
pages/index.js Normal file
View file

@ -0,0 +1,10 @@
import React from 'react';
import Layout from 'components/layout';
export default function Home() {
return (
<Layout>
Hello.
</Layout>
);
}