diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fd6c194 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:18-alpine + +ARG NODE_ENV=production +ENV NODE_ENV=${NODE_ENV} + +WORKDIR /usr/src/app +COPY package*.json ./ +COPY ./ ./ + +RUN npm install + +RUN npm run build + +EXPOSE 3000 + +CMD [ "npm", "run", "start" ] \ No newline at end of file diff --git a/next.config.js b/next.config.js index bfdacd1..4e1e30a 100644 --- a/next.config.js +++ b/next.config.js @@ -1,5 +1,6 @@ /** @type {import('next').NextConfig} */ const nextConfig = { + output: 'standalone', reactStrictMode: true, swcMinify: true, trailingSlash: true, diff --git a/src/back-features/schedule.ts b/src/back-features/schedule.ts index 8511e7c..0aee557 100644 --- a/src/back-features/schedule.ts +++ b/src/back-features/schedule.ts @@ -2,12 +2,17 @@ const SCHEDULE_COLLECTION = "schedule"; import db from '../utils/db'; const getSchedule = async () => { - const scheduleQuerySnapshot = await db.collection(SCHEDULE_COLLECTION).get(); - const schedule: any[] = []; // eslint-disable-line - scheduleQuerySnapshot.forEach( - (doc) => schedule.push({ ...doc.data() }) - ); - return schedule; + try { + + const scheduleQuerySnapshot = await db.collection(SCHEDULE_COLLECTION).get(); + const schedule: any[] = []; // eslint-disable-line + scheduleQuerySnapshot.forEach( + (doc) => schedule.push({ ...doc.data() }) + ); + return schedule; + } catch (error) { + console.error(error); + } } diff --git a/src/back-features/speakers.ts b/src/back-features/speakers.ts index a4a4901..ef9fcff 100644 --- a/src/back-features/speakers.ts +++ b/src/back-features/speakers.ts @@ -17,8 +17,6 @@ interface SpeakerPayload { } const createSpeaker = async ({ key, id, companyTitle, mini_bio, name, photo, tech, title, topic, location }: SpeakerPayload) => { - - const data = { id, companyTitle, mini_bio, name, photo, tech, title, topic, location, }; @@ -59,17 +57,21 @@ const createSpeaker = async ({ key, id, companyTitle, mini_bio, name, photo, tec } const getSpeaker = async () => { - - const speakersQuerySnapshot = await db.collection(SPEAKERS_COLLECTION).get(); - const speakers: { key: string }[] = []; - speakersQuerySnapshot.forEach( - (doc) => speakers.push({ - ...doc.data(), - key: doc.id, - }) - ); - - return speakers; + try { + + const speakersQuerySnapshot = await db.collection(SPEAKERS_COLLECTION).get(); + const speakers: { key: string }[] = []; + speakersQuerySnapshot.forEach( + (doc) => speakers.push({ + ...doc.data(), + key: doc.id, + }) + ); + + return speakers; + } catch (error) { + console.error(error) + } } diff --git a/src/back-features/sponsors.ts b/src/back-features/sponsors.ts index bdf68a8..eb0b1b5 100644 --- a/src/back-features/sponsors.ts +++ b/src/back-features/sponsors.ts @@ -2,12 +2,16 @@ const SPONSORS_COLLECTION = "sponsors"; import db from '../utils/db'; const getSponsors = async () => { - const sponsorsQuerySnapshot = await db.collection(SPONSORS_COLLECTION).get(); - const sponsors: any = {}; // eslint-disable-line - sponsorsQuerySnapshot.forEach( - (doc) => sponsors[doc.id.trim()] = { ...doc.data() } - ); - return sponsors; + try { + const sponsorsQuerySnapshot = await db.collection(SPONSORS_COLLECTION).get(); + const sponsors: any = {}; // eslint-disable-line + sponsorsQuerySnapshot.forEach( + (doc) => sponsors[doc.id.trim()] = { ...doc.data() } + ); + return sponsors; + } catch (error) { + console.error(error); + } } diff --git a/src/front-features/schedule.ts b/src/front-features/schedule.ts index 559ea1f..862f4f2 100644 --- a/src/front-features/schedule.ts +++ b/src/front-features/schedule.ts @@ -2,10 +2,13 @@ import { server } from 'helpers/config'; import { Schedule } from 'models/schedule'; export const getSchedule = async (): Promise => { - const url = `${server}/api/v1/schedule`; - - //console.log(url); - const res = await fetch(url); - const schedule = await res.json(); - return schedule; + try { + const url = `${server}/api/v1/schedule`; + const res = await fetch(url); + const schedule = await res.json(); + return schedule; + } catch (error) { + console.error(error); + return []; + } } \ No newline at end of file diff --git a/src/front-features/speakers.ts b/src/front-features/speakers.ts index 0f4ae40..ef9ce5b 100644 --- a/src/front-features/speakers.ts +++ b/src/front-features/speakers.ts @@ -2,10 +2,13 @@ import { server } from 'helpers/config'; import { Speaker } from 'models/speaker'; export const getSpeakers = async (): Promise => { - const url = `${server}/api/v1/speakers`; - - //console.log(url); - const res = await fetch(url); - const speakers = await res.json(); - return speakers; + try { + const url = `${server}/api/v1/speakers`; + const res = await fetch(url); + const speakers = await res.json(); + return speakers; + } catch (error) { + console.log(error) + return []; + } } \ No newline at end of file diff --git a/src/front-features/sponsors.ts b/src/front-features/sponsors.ts index 032f4cf..76705aa 100644 --- a/src/front-features/sponsors.ts +++ b/src/front-features/sponsors.ts @@ -1,9 +1,13 @@ import { server } from 'helpers/config'; -import { Sponsor } from 'models/sponsor'; import { SponsorLevel } from 'models/sponsor-level'; -export const getSponsors = async (): Promise<{ [key: string]: SponsorLevel }> => { - const res = await fetch(`${server}/api/v1/sponsors`) - const sponsors = await res.json(); - return sponsors; +export const getSponsors = async (): Promise<{ [key: string]: SponsorLevel } | null> => { + try { + const res = await fetch(`${server}/api/v1/sponsors`) + const sponsors = await res.json(); + return sponsors; + } catch (error) { + console.error(error); + return null; + } } \ No newline at end of file diff --git a/src/utils/db/index.ts b/src/utils/db/index.ts index ce522b1..eca2180 100644 --- a/src/utils/db/index.ts +++ b/src/utils/db/index.ts @@ -4,8 +4,10 @@ interface Database extends admin.firestore.Firestore { } let db: Database; + if (!admin.apps.length) { + if (!process.env.FIREBASE_SERVICE_ACCOUNT) { throw new Error('FIREBASE_SERVICE_ACCOUNT is not defined'); } @@ -26,5 +28,4 @@ else { db = admin.firestore(); } - export default db; \ No newline at end of file