2022-03-26 00:39:38 +00:00
require ( "dotenv" ) . config ( { path : "../../.env" } ) ;
2022-08-26 16:31:55 +00:00
const CopyWebpackPlugin = require ( "copy-webpack-plugin" ) ;
2022-11-11 09:47:11 +00:00
const { withSentryConfig } = require ( "@sentry/nextjs" ) ;
2022-11-22 13:33:17 +00:00
const os = require ( "os" ) ;
2022-03-09 22:56:05 +00:00
const withTM = require ( "next-transpile-modules" ) ( [
2022-03-23 22:00:30 +00:00
"@calcom/app-store" ,
"@calcom/core" ,
2022-06-28 20:40:58 +00:00
"@calcom/dayjs" ,
2022-06-06 17:49:56 +00:00
"@calcom/emails" ,
2022-03-31 08:45:47 +00:00
"@calcom/embed-core" ,
2022-07-06 20:34:49 +00:00
"@calcom/embed-react" ,
2022-05-05 14:29:49 +00:00
"@calcom/embed-snippet" ,
2022-07-28 19:58:26 +00:00
"@calcom/features" ,
2022-07-22 17:27:06 +00:00
"@calcom/lib" ,
"@calcom/prisma" ,
"@calcom/trpc" ,
"@calcom/ui" ,
2022-03-09 22:56:05 +00:00
] ) ;
2022-07-27 20:19:59 +00:00
const { withAxiom } = require ( "next-axiom" ) ;
2021-09-23 08:49:17 +00:00
const { i18n } = require ( "./next-i18next.config" ) ;
2021-04-26 12:01:21 +00:00
2022-06-03 16:50:48 +00:00
if ( ! process . env . NEXTAUTH _SECRET ) throw new Error ( "Please set NEXTAUTH_SECRET" ) ;
if ( ! process . env . CALENDSO _ENCRYPTION _KEY ) throw new Error ( "Please set CALENDSO_ENCRYPTION_KEY" ) ;
2021-09-21 20:18:41 +00:00
// So we can test deploy previews preview
2022-03-26 00:39:38 +00:00
if ( process . env . VERCEL _URL && ! process . env . NEXT _PUBLIC _WEBAPP _URL ) {
process . env . NEXT _PUBLIC _WEBAPP _URL = "https://" + process . env . VERCEL _URL ;
2021-09-21 20:18:41 +00:00
}
2022-11-08 15:04:18 +00:00
// Check for configuration of NEXTAUTH_URL before overriding
if ( ! process . env . NEXTAUTH _URL && process . env . NEXT _PUBLIC _WEBAPP _URL ) {
2022-03-26 00:39:38 +00:00
process . env . NEXTAUTH _URL = process . env . NEXT _PUBLIC _WEBAPP _URL + "/api/auth" ;
2021-06-07 16:38:46 +00:00
}
2022-03-26 00:39:38 +00:00
if ( ! process . env . NEXT _PUBLIC _WEBSITE _URL ) {
process . env . NEXT _PUBLIC _WEBSITE _URL = process . env . NEXT _PUBLIC _WEBAPP _URL ;
2021-09-22 18:36:13 +00:00
}
2021-06-07 16:38:46 +00:00
2021-07-20 18:18:26 +00:00
if ( ! process . env . EMAIL _FROM ) {
console . warn (
"\x1b[33mwarn" ,
"\x1b[0m" ,
"EMAIL_FROM environment variable is not set, this may indicate mailing is currently disabled. Please refer to the .env.example file."
) ;
2021-05-27 22:10:20 +00:00
}
2022-06-03 18:48:47 +00:00
if ( ! process . env . NEXTAUTH _URL ) throw new Error ( "Please set NEXTAUTH_URL" ) ;
2021-05-04 20:31:15 +00:00
const validJson = ( jsonString ) => {
2021-07-20 18:18:26 +00:00
try {
const o = JSON . parse ( jsonString ) ;
if ( o && typeof o === "object" ) {
return o ;
2021-05-04 20:31:15 +00:00
}
2021-07-20 18:18:26 +00:00
} catch ( e ) {
console . error ( e ) ;
}
return false ;
} ;
2021-05-04 20:31:15 +00:00
2021-07-20 18:18:26 +00:00
if ( process . env . GOOGLE _API _CREDENTIALS && ! validJson ( process . env . GOOGLE _API _CREDENTIALS ) ) {
console . warn (
"\x1b[33mwarn" ,
"\x1b[0m" ,
'- Disabled \'Google Calendar\' integration. Reason: Invalid value for GOOGLE_API_CREDENTIALS environment variable. When set, this value needs to contain valid JSON like {"web":{"client_id":"<clid>","client_secret":"<secret>","redirect_uris":["<yourhost>/api/integrations/googlecalendar/callback>"]}. You can download this JSON from your OAuth Client @ https://console.cloud.google.com/apis/credentials.'
) ;
2021-05-04 20:31:15 +00:00
}
2021-10-20 09:08:58 +00:00
const plugins = [ ] ;
if ( process . env . ANALYZE === "true" ) {
// only load dependency if env `ANALYZE` was set
const withBundleAnalyzer = require ( "@next/bundle-analyzer" ) ( {
enabled : true ,
} ) ;
plugins . push ( withBundleAnalyzer ) ;
}
plugins . push ( withTM ) ;
2022-07-27 20:19:59 +00:00
plugins . push ( withAxiom ) ;
2021-09-29 14:36:58 +00:00
2022-03-26 00:39:38 +00:00
/** @type {import("next").NextConfig} */
const nextConfig = {
2021-09-23 08:49:17 +00:00
i18n ,
2022-11-18 14:23:14 +00:00
productionBrowserSourceMaps : true ,
2022-08-30 21:24:17 +00:00
/* We already do type check on GH actions */
typescript : {
ignoreBuildErrors : ! ! process . env . CI ,
} ,
/* We already do linting on GH actions */
2022-08-30 11:50:34 +00:00
eslint : {
2022-08-30 21:24:17 +00:00
ignoreDuringBuilds : ! ! process . env . CI ,
2022-08-30 11:50:34 +00:00
} ,
2022-11-18 14:23:14 +00:00
images : {
unoptimized : true ,
2022-08-26 16:31:55 +00:00
} ,
2021-09-09 13:51:06 +00:00
webpack : ( config ) => {
2022-08-26 16:31:55 +00:00
config . plugins . push (
new CopyWebpackPlugin ( {
patterns : [
{
2022-08-31 09:26:16 +00:00
from : "../../packages/app-store/**/static/**" ,
2022-08-26 16:31:55 +00:00
to ( { context , absoluteFilename } ) {
2022-11-21 14:33:19 +00:00
// Adds compatibility for windows path
2022-11-22 13:33:17 +00:00
if ( os . platform ( ) === "win32" ) {
const absoluteFilenameWin = absoluteFilename . replaceAll ( "\\" , "/" ) ;
const contextWin = context . replaceAll ( "\\" , "/" ) ;
const appName = /app-store\/(.*)\/static/ . exec ( absoluteFilenameWin ) ;
return Promise . resolve ( ` ${ contextWin } /public/app-store/ ${ appName [ 1 ] } /[name][ext] ` ) ;
}
const appName = /app-store\/(.*)\/static/ . exec ( absoluteFilename ) ;
return Promise . resolve ( ` ${ context } /public/app-store/ ${ appName [ 1 ] } /[name][ext] ` ) ;
2022-08-26 16:31:55 +00:00
} ,
} ,
] ,
} )
) ;
2021-09-09 13:51:06 +00:00
config . resolve . fallback = {
... config . resolve . fallback , // if you miss it, all the other options in fallback, specified
// by next.js will be dropped. Doesn't make much sense, but how it is
fs : false ,
} ;
2022-08-11 16:36:30 +00:00
/ * *
* TODO : Find more possible barrels for this project .
* @ see https : //github.com/vercel/next.js/issues/12557#issuecomment-1196931845
* * /
config . module . rules . push ( {
test : [ /lib\/.*.tsx?/i ] ,
sideEffects : false ,
} ) ;
2021-09-09 13:51:06 +00:00
return config ;
} ,
2022-01-11 08:54:02 +00:00
async rewrites ( ) {
2022-07-14 20:56:00 +00:00
return [
{
source : "/:user/avatar.png" ,
destination : "/api/user/avatar?username=:user" ,
} ,
{
source : "/team/:teamname/avatar.png" ,
destination : "/api/user/avatar?teamname=:teamname" ,
} ,
2022-07-15 11:46:05 +00:00
{
2022-10-19 21:25:03 +00:00
source : "/forms/:formQuery*" ,
destination : "/apps/routing-forms/routing-link/:formQuery*" ,
2022-07-15 11:46:05 +00:00
} ,
2022-08-13 11:04:57 +00:00
{
source : "/router" ,
2022-09-22 17:23:43 +00:00
destination : "/apps/routing-forms/router" ,
2022-08-13 11:04:57 +00:00
} ,
2022-07-14 20:56:00 +00:00
/ * T O D O : h a v e t h e s e f i l e s b e i n g s e r v e d f r o m a n o t h e r d e p l o y m e n t o r C D N {
source : "/embed/embed.js" ,
destination : process . env . NEXT _PUBLIC _EMBED _LIB _URL ? ,
} , * /
] ;
2022-01-11 08:54:02 +00:00
} ,
2021-05-07 15:04:56 +00:00
async redirects ( ) {
2022-05-02 20:39:35 +00:00
const redirects = [
2022-08-26 16:31:55 +00:00
{
source : "/api/app-store/:path*" ,
destination : "/app-store/:path*" ,
permanent : true ,
} ,
2022-10-12 12:52:59 +00:00
{
source : "/auth/signup" ,
destination : "/signup" ,
permanent : true ,
} ,
2021-05-07 15:04:56 +00:00
{
2021-07-20 18:18:26 +00:00
source : "/settings" ,
2022-09-15 11:09:06 +00:00
destination : "/settings/my-account/profile" ,
2021-05-07 15:04:56 +00:00
permanent : true ,
2021-07-20 18:18:26 +00:00
} ,
2022-09-19 14:38:21 +00:00
{
source : "/settings/teams" ,
destination : "/teams" ,
permanent : true ,
} ,
2022-08-26 00:11:41 +00:00
/* V2 testers get redirected to the new settings */
{
source : "/settings/profile" ,
destination : "/settings/my-account/profile" ,
permanent : false ,
} ,
2022-08-30 19:46:52 +00:00
{
source : "/settings/security" ,
destination : "/settings/security/password" ,
permanent : false ,
} ,
2021-09-29 21:33:18 +00:00
{
source : "/bookings" ,
destination : "/bookings/upcoming" ,
permanent : true ,
} ,
2022-02-15 15:13:27 +00:00
{
2022-03-26 00:39:38 +00:00
source : "/call/:path*" ,
destination : "/video/:path*" ,
permanent : false ,
} ,
2022-08-16 22:01:38 +00:00
/* Attempt to mitigate DDoS attack */
{
source : "/api/auth/:path*" ,
has : [
{
2022-08-16 23:38:26 +00:00
type : "query" ,
key : "callbackUrl" ,
// prettier-ignore
value : "^(?!https?:\/\/).*$" ,
2022-08-16 22:01:38 +00:00
} ,
] ,
destination : "/404" ,
permanent : false ,
} ,
2021-07-20 18:18:26 +00:00
] ;
2022-05-02 20:39:35 +00:00
if ( process . env . NEXT _PUBLIC _WEBAPP _URL === "https://app.cal.com" ) {
redirects . push (
{
source : "/apps/dailyvideo" ,
destination : "/apps/daily-video" ,
permanent : true ,
} ,
{
source : "/apps/huddle01_video" ,
destination : "/apps/huddle01" ,
permanent : true ,
} ,
{
source : "/apps/jitsi_video" ,
destination : "/apps/jitsi" ,
permanent : true ,
}
) ;
}
return redirects ;
2021-07-20 18:18:26 +00:00
} ,
2022-11-11 09:47:11 +00:00
} ;
const sentryWebpackPluginOptions = {
silent : true , // Suppresses all logs
2022-03-26 00:39:38 +00:00
} ;
2022-11-11 09:47:11 +00:00
const moduleExports = ( ) => plugins . reduce ( ( acc , next ) => next ( acc ) , nextConfig ) ;
2022-11-18 14:23:14 +00:00
if ( process . env . NEXT _PUBLIC _SENTRY _DSN ) {
nextConfig . sentry = {
hideSourceMaps : true ,
// Prevents Sentry from running on this Edge function, where Sentry doesn't work yet (build whould crash the api route).
excludeServerRoutes : [ /\/api\/social\/og\/image\/?/ ] ,
} ;
}
2022-11-11 09:47:11 +00:00
// Sentry should be the last thing to export to catch everything right
module . exports = process . env . NEXT _PUBLIC _SENTRY _DSN
? withSentryConfig ( moduleExports , sentryWebpackPluginOptions )
: moduleExports ;