diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6e070ff --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.env +node_modules +dist +dockercompose +dockerfile \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8c0f08a..2fc2791 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .env -dockercompose.yaml \ No newline at end of file +dockercompose.yaml +dist \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e69de29..0741ad5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:18-alpine AS builder + +WORKDIR /app +COPY package*.json ./ +RUN npm install + +COPY . . + +RUN npm run build + + +FROM node:18-alpine AS runtime + +WORKDIR /app +COPY package*.json ./ +RUN npm ci --omit=dev +COPY --from=builder /app/dist ./dist +COPY --from=builder /app/static ./static +ENV NODE_ENV=production +EXPOSE 3000 +CMD ["node", "./dist/index.js"] \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bfd7c84..b2794a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ "devDependencies": { "@types/express": "^5.0.3", "@types/node": "^24.0.4", - "@types/nodemailer": "^6.4.17" + "@types/nodemailer": "^6.4.17", + "typescript": "^5.8.3" } }, "node_modules/@mongodb-js/saslprep": { @@ -1113,6 +1114,20 @@ "node": ">= 0.6" } }, + "node_modules/typescript": { + "version": "5.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", + "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/undici-types": { "version": "7.8.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.8.0.tgz", diff --git a/package.json b/package.json index f500c25..7c56084 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "devDependencies": { "@types/express": "^5.0.3", "@types/node": "^24.0.4", - "@types/nodemailer": "^6.4.17" + "@types/nodemailer": "^6.4.17", + "typescript": "^5.8.3" } } diff --git a/src/formHandler.ts b/src/formHandler.ts index fe6db97..d4ea25e 100644 --- a/src/formHandler.ts +++ b/src/formHandler.ts @@ -1,6 +1,6 @@ import nodemailer from 'nodemailer'; import type { Transporter, SendMailOptions } from 'nodemailer'; -import { Report, Report as ReportSchema } from './models/report'; +import { Report, Report as ReportSchema } from './models/report.js'; export interface Fault { coach: string; @@ -15,7 +15,7 @@ export interface Report { faults: Fault[]; } -export async function handleFormData(data) { +export async function handleFormData(data: any) { // Uploads form data to database and emails // to defined subscribers. diff --git a/src/index.ts b/src/index.ts index 21ea8a8..ffbcc88 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import express, { Request, Response } from "express"; -import { handleFormData } from "./formHandler"; -import { initDb } from "./database"; +import { handleFormData } from "./formHandler.js"; +import { initDb } from "./database.js"; const app = express(); const port = process.env.port || 3000; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..ad9bca6 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ES2020", + "moduleResolution": "node", + "outDir": "dist", + "rootDir": "src", + "strict": true, + "esModuleInterop": true, + "removeComments": true, + "resolveJsonModule": true + }, + "include": ["src/**/*"] +}