Skip to content

Commit

Permalink
Typescript deploy on heroku (#8)
Browse files Browse the repository at this point in the history
* improve interface types on body request

* Create tsconfig.json

* Update package.json

* Create Procfile

* fixed running only on localhost
  • Loading branch information
RodrigoDornelles authored Aug 22, 2021
1 parent b1bd274 commit 72af77a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: npm start
14 changes: 11 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"];
Expand Down Expand Up @@ -100,4 +108,4 @@ api.post('/', async (request, response) => {
});
});

api.listen(env.PORT);
api.listen(env.PORT, '0.0.0.0');
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"baseUrl": "./",
"module": "commonjs",
"outDir": "./dist",
"strict": true,
"target": "ES2019",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"removeComments": true,
},
"include": [
"./index.ts"
]
}

0 comments on commit 72af77a

Please sign in to comment.