-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: email service * fix: pnpm-lock * chore: removed sanitize
- Loading branch information
1 parent
291eb97
commit d3e7345
Showing
12 changed files
with
197 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# SMTP server credentials | ||
EMAIL_HOST="" | ||
EMAIL_PORT="" | ||
EMAIL_USER="" | ||
EMAIL_PASS="" | ||
|
||
# Email addresses: from and to | ||
EMAIL_FROM="" # Name of the sender <info@yourdomain.com> | ||
|
||
# TOKEN | ||
EMAIL_TOKEN="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import config from '@next-orders/eslint/nuxt.mjs' | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// https://nitro.unjs.io/config | ||
export default defineNitroConfig({ | ||
srcDir: 'server', | ||
runtimeConfig: { | ||
nitro: { | ||
envPrefix: 'EMAIL_', | ||
}, | ||
token: '', | ||
host: '', | ||
port: 0, | ||
user: '', | ||
pass: '', | ||
from: '', | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@next-orders/email", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"build": "nitro build", | ||
"dev": "nitro dev", | ||
"prepare": "nitro prepare", | ||
"preview": "node .output/server/index.mjs", | ||
"clean": "turbo clean", | ||
"clean:modules": "turbo clean:modules && rm -rf .turbo node_modules", | ||
"lint": "eslint .", | ||
"lint:fix": "eslint --fix .", | ||
"typecheck": "nitro prepare", | ||
"postinstall": "nitro prepare" | ||
}, | ||
"dependencies": { | ||
"nodemailer": "^6.9.15" | ||
}, | ||
"devDependencies": { | ||
"@next-orders/eslint": "workspace:*", | ||
"@types/nodemailer": "^6.4.16", | ||
"nitropack": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { createTransport } from 'nodemailer' | ||
|
||
export default eventHandler(async (event) => { | ||
try { | ||
const logger = useLogger('email') | ||
const { host, port, user, pass, from, token } = useRuntimeConfig(event) | ||
const key = getRouterParam(event, 'token') | ||
|
||
if (!token || token !== key) { | ||
throw createError({ | ||
statusCode: 401, | ||
statusMessage: 'Invalid token', | ||
}) | ||
} | ||
|
||
const body = await readBody(event) | ||
|
||
if (!body?.to || !body?.subject || !body?.html) { | ||
throw createError({ | ||
statusCode: 400, | ||
statusMessage: 'Missing data', | ||
}) | ||
} | ||
|
||
const transporter = createTransport({ | ||
host, | ||
port: Number(port), | ||
secure: Number(port) === 465, | ||
tls: { | ||
rejectUnauthorized: false, | ||
}, | ||
auth: { user, pass }, | ||
}) | ||
|
||
const info = await transporter.sendMail({ | ||
from, | ||
to: body.to, | ||
subject: body.subject, | ||
text: body.html, | ||
html: body.html, | ||
}) | ||
logger.log('Response from SMTP server:', info?.accepted?.length > 0 ? 'SUCCESS' : 'FAILED', info?.response, info?.messageId) | ||
|
||
return { | ||
ok: true, | ||
} | ||
} catch (error) { | ||
throw errorResolver(error) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { H3Error } from 'h3' | ||
|
||
const logger = useLogger('error') | ||
|
||
export function errorResolver(exception: unknown) { | ||
if (exception instanceof H3Error) { | ||
throw exception | ||
} | ||
|
||
// Ok, something intereresting happened | ||
logger.error(exception) | ||
|
||
return createError({ | ||
statusCode: 500, | ||
statusMessage: 'Internal server error', | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { consola } from 'consola' | ||
|
||
export function useLogger(tag?: string) { | ||
return tag ? consola.withTag(tag) : consola | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// https://nitro.unjs.io/guide/typescript | ||
{ | ||
"extends": "./.nitro/types/tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
ARG NODE=node:22.10.0-alpine | ||
|
||
################# Base builder ############## | ||
|
||
FROM $NODE AS builder | ||
WORKDIR /app | ||
|
||
ENV PNPM_HOME="/pnpm" | ||
ENV PATH="$PNPM_HOME:$PATH" | ||
RUN corepack enable | ||
|
||
COPY . . | ||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile \ | ||
&& pnpm build --filter @next-orders/email | ||
|
||
################# App ############## | ||
|
||
FROM $NODE | ||
WORKDIR /app | ||
COPY --from=builder /app/apps/food/.output . | ||
|
||
ARG VERSION=nightly | ||
ENV VERSION=${VERSION} | ||
ENV NODE_ENV=production | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["/app/server/index.mjs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.