Skip to content

Commit

Permalink
added more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Apr 30, 2023
1 parent 001a53e commit 8cc2eda
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const HOME_HOSTNAMES = new Set([
// comment for better diffs
"dub.sh",
"preview.dub.sh",
"localhost",
"localhost:3000",
]);

Expand Down
2 changes: 2 additions & 0 deletions lib/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ export const getStats = async ({
// 3. interval is not defined
// 4. there's a connection to MySQL
if (endpoint === "clicks" && key !== "_root" && !interval && conn) {
console.log("Getting all-time clicks count from MySQL", domain, key);
const response = await conn.execute(
"SELECT clicks FROM Link WHERE domain = ? AND `key` = ?",
[domain, key],
);
console.log("MySQL response", response);
try {
const clicks = response.rows[0]["clicks"];
return clicks || "0";
Expand Down
4 changes: 2 additions & 2 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
RootMiddleware,
} from "@/lib/middleware";
import { parse } from "@/lib/middleware/utils";
import { isReservedKey } from "./lib/utils";
import { isHomeHostname, isReservedKey } from "./lib/utils";

export const config = {
matcher: [
Expand All @@ -26,7 +26,7 @@ export const config = {

export default async function middleware(req: NextRequest, ev: NextFetchEvent) {
const { domain, path, key } = parse(req);
const home = domain === "dub.sh" || domain.endsWith(".vercel.app");
const home = isHomeHostname(domain);

// for App (app.dub.sh and app.localhost:3000)
if (domain === "app.dub.sh" || domain === "app.localhost:3000") {
Expand Down

0 comments on commit 8cc2eda

Please sign in to comment.