Skip to content

Commit

Permalink
Merge pull request #661 from WestpacGEL/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jaortiz authored Jan 18, 2024
2 parents ba79249 + 9aaac74 commit f73c031
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
50 changes: 50 additions & 0 deletions apps/site/src/app/api/logs/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import crypto from 'crypto';

import { sql } from '@vercel/postgres';
import { NextResponse } from 'next/server';

export async function POST(request: Request) {
const response = NextResponse.json({});
// eslint-disable-next-line turbo/no-undeclared-env-vars
response.headers.set('x-vercel-verify', process.env.LOG_DRAIN_VERIFY || '');

return response;
// if (process.env.NODE_ENV === 'production') {
// if (typeof process.env.VERCEL_LOG_DRAIN_SECRET != 'string') {
// throw new Error('No integration secret found');
// }

// if (!verifySignature(request)) {
// return NextResponse.json({
// code: 'invalid_signature',
// error: "signature didn't match",
// });
// }

// try {
// const logs = await request.json();

// for (const log of logs) {
// const {
// id,
// timestamp,
// proxy: { clientIp, referer },
// } = log;

// await sql`INSERT INTO logs_drain(log_id, time, request_ip, request_url) VALUES (${id}, TO_TIMESTAMP(${timestamp}::bigint/1000), ${clientIp}, ${referer})`;
// }
// } catch (error) {
// return NextResponse.json({ error }, { status: 500 });
// }
// }

// return NextResponse.json({ message: 'Logged successfully' });
}

async function verifySignature(request: Request) {
const signature = crypto
.createHmac('sha1', process.env.VERCEL_LOG_DRAIN_SECRET || '')
.update(JSON.stringify(request.body))
.digest('hex');
return signature === request.headers.get('x-vercel-signature');
}
13 changes: 1 addition & 12 deletions apps/site/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import { sql } from '@vercel/postgres';
import { NextRequest, NextResponse } from 'next/server';

export async function middleware(request: NextRequest) {
// logging
if (process.env.NODE_ENV === 'production') {
try {
sql`INSERT INTO logs(url, ip) VALUES (${request.url}, ${request.ip || ''})`;
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
}

export function middleware(request: NextRequest) {
const nonce = Buffer.from(crypto.randomUUID()).toString('base64');

// We need unsafe-inline for style-src in order to make nextjs/image to work
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://turbo.build/schema.json",
"globalEnv": ["NODE_ENV", "NEXT_PUBLIC_GIT_REPO_OWNER", "NEXT_PUBLIC_GIT_REPO_SLUG"],
"globalEnv": ["NODE_ENV", "NEXT_PUBLIC_GIT_REPO_OWNER", "NEXT_PUBLIC_GIT_REPO_SLUG", "VERCEL_LOG_DRAIN_SECRET"],
"pipeline": {
"build": {
"dependsOn": ["^build"],
Expand Down

1 comment on commit f73c031

@vercel
Copy link

@vercel vercel bot commented on f73c031 Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

gel-next-site – ./apps/site

gel-next-site.vercel.app
gel-next-site-westpacgel.vercel.app
gel-next-site-git-main-westpacgel.vercel.app

Please sign in to comment.