Skip to content

Commit

Permalink
ai tts and stt
Browse files Browse the repository at this point in the history
  • Loading branch information
urdadx committed Jul 10, 2024
1 parent 1eab414 commit f3724f3
Show file tree
Hide file tree
Showing 43 changed files with 2,991 additions and 447 deletions.
14 changes: 8 additions & 6 deletions .env
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
REACT_APP_RAPID_API_URL=https://judge0-ce.p.rapidapi.com/submissions
REACT_APP_RAPID_API_HOST=judge0-ce.p.rapidapi.com
REACT_APP_RAPID_API_KEY=0e58c401femsh4bc6914c8b658f0p1108a6jsn88ac8d898095

NODE_ENV=development
NEXT_PUBLIC_DEV_API_URL=https://wanderer-ksny.onrender.com
NEXT_PUBLIC_PROD_API_URL=https://wanderer.vercel.app

NODE_ENV=production
NEXT_PUBLIC_DEV_API_URL=https://wandererappserver.azurewebsites.net
OPENAI_API_KEY=

TOGETHER_API_KEY=a497a1c5ef389f6374a50a68e195971ce496b6767e3c094c6c8ba8cfe776b8a3
HELICONE_API_KEY=pk-helicone-f3b54ji-wutelda-tmwqwsy-ujccsqi
NEXT_PUBLIC_PROD_API_URL=https://wandererappserver.azurewebsites.net


GROQ_API_KEY=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
GROQ_API_KEY=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
DEEPGRAM_API_KEY=2dbf43a3cf8ade46caa1690422587c2c4389b9ee
DEEPGRAM_STT_DOMAIN=https://api.deepgram.com
DEEPGRAM_ENV=development
77 changes: 77 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { NextResponse, type NextRequest } from 'next/server';

const corsOptions: {
allowedMethods: string[];
allowedOrigins: string[];
allowedHeaders: string[];
exposedHeaders: string[];
maxAge?: number;
credentials: boolean;
} = {
allowedMethods: (process.env?.ALLOWED_METHODS || '').split(','),
allowedOrigins: (process.env?.ALLOWED_ORIGIN || '').split(','),
allowedHeaders: (process.env?.ALLOWED_HEADERS || '').split(','),
exposedHeaders: (process.env?.EXPOSED_HEADERS || '').split(','),
maxAge:
(process.env?.PREFLIGHT_MAX_AGE &&
parseInt(process.env?.PREFLIGHT_MAX_AGE)) ||
undefined, // 60 * 60 * 24 * 30, // 30 days
credentials: process.env?.CREDENTIALS == 'true',
};

/**
* Middleware function that handles CORS configuration for API routes.
*
* This middleware function is responsible for setting the appropriate CORS headers
* on the response, based on the configured CORS options. It checks the origin of
* the request and sets the `Access-Control-Allow-Origin` header accordingly. It
* also sets the other CORS-related headers, such as `Access-Control-Allow-Credentials`,
* `Access-Control-Allow-Methods`, `Access-Control-Allow-Headers`, and
* `Access-Control-Expose-Headers`.
*
* The middleware function is configured to be applied to all API routes, as defined
* by the `config` object at the end of the file.
*/
export function middleware(request: NextRequest) {
// Response
const response = NextResponse.next();

// Allowed origins check
const origin = request.headers.get('origin') ?? '';
if (
corsOptions.allowedOrigins.includes('*') ||
corsOptions.allowedOrigins.includes(origin)
) {
response.headers.set('Access-Control-Allow-Origin', origin);
}

// Set default CORS headers
response.headers.set(
'Access-Control-Allow-Credentials',
corsOptions.credentials.toString()
);
response.headers.set(
'Access-Control-Allow-Methods',
corsOptions.allowedMethods.join(',')
);
response.headers.set(
'Access-Control-Allow-Headers',
corsOptions.allowedHeaders.join(',')
);
response.headers.set(
'Access-Control-Expose-Headers',
corsOptions.exposedHeaders.join(',')
);
response.headers.set(
'Access-Control-Max-Age',
corsOptions.maxAge?.toString() ?? ''
);

// Return
return response;
}

// See "Matching Paths" below to learn more
export const config = {
matcher: '/api/:path*',
};
Loading

0 comments on commit f3724f3

Please sign in to comment.