diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..063b78f --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: npm start diff --git a/index.ts b/index.ts index efd965a..c5aa108 100644 --- a/index.ts +++ b/index.ts @@ -43,6 +43,14 @@ const env = load({ TEXT_RESPONSE_FAIL_CAPTCHA: String }); +interface Body { + "g-recaptcha-response"?: string, + "h-captcha-response"?: string, + "comment": string, + "email": string, + "name": string +} + const transporter = createTransport({ host: env.MAIL_HOST , port: env.MAIL_PORT, @@ -59,8 +67,8 @@ api.register(cors, { optionsSuccessStatus: 200 }); -api.post('/', async (request, response) => { - const recaptcha : string = request.body["g-recaptcha-response"] ?? request.body["h-captcha-response"]; +api.post<{Body: Body}>('/', async (request, response) => { + const recaptcha : string = request.body["g-recaptcha-response"] ?? request.body["h-captcha-response"] ?? ''; const comment : string = request.body["comment"]; const email : string = request.body["email"]; const name : string = request.body["name"]; @@ -100,4 +108,4 @@ api.post('/', async (request, response) => { }); }); -api.listen(env.PORT); +api.listen(env.PORT, '0.0.0.0'); diff --git a/package.json b/package.json index 96d68cd..80f9f6c 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,11 @@ { "name": "mail-send-api", - "version": "2.0.0", + "version": "2.0.1", "description": "free software to send mails with form using recaptcha using api request", - "main": "index.js", + "main": "dist/index.js", "scripts": { - "start": "node index.js", - "build": "tsc index.ts", - "postinstall": "npm run build;npm start" + "start": "node .", + "build": "tsc" }, "repository": { "type": "git", diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..26776f0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "baseUrl": "./", + "module": "commonjs", + "outDir": "./dist", + "strict": true, + "target": "ES2019", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "removeComments": true, + }, + "include": [ + "./index.ts" + ] +}