Capture pushState events.

This commit is contained in:
Mike Cao 2020-07-18 22:51:17 -07:00
parent 58a1c63407
commit eebf145efc
6 changed files with 81 additions and 48 deletions

View file

@ -5,7 +5,7 @@ import { allowPost } from 'lib/middleware';
export default async (req, res) => {
await allowPost(req, res);
let result = { success: 0, time: Date.now() };
let result = { success: 0 };
const {
website_id,
@ -23,6 +23,7 @@ export default async (req, res) => {
if (website) {
const session = await getSession(session_id);
const time = Date.now();
if (!session) {
await createSession(website_id, session_id, {
@ -40,7 +41,8 @@ export default async (req, res) => {
success: 1,
session_id,
website_id,
hash: hash(`${website_id}${session_id}${result.time}`),
time,
hash: hash(`${website_id}${session_id}${time}`),
};
}
}

View file

@ -1,14 +1,19 @@
import React from 'react';
import Layout from 'components/layout';
import Link from 'next/link';
export default function Home() {
return (
<Layout>
Hello.
<br />
<a href="/?q=abc">abc</a>
<Link href="/?q=abc">
<a>abc</a>
</Link>
<br />
<a href="/?q=123">123</a>
<Link href="/?q=123">
<a>123</a>
</Link>
</Layout>
);
}