Skip to content

Commit

Permalink
267th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Feb 21, 2024
1 parent c47c8c8 commit 9cacf31
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ Set your local environment variables.

SITE_URL: process.env.SITE_URL || 'http://127.0.0.1:5173',

MONGODB_URL: process.env.MONGODB_URL || 'xxx',
REDIS_URL: process.env.REDIS_URL || 'xxx',
CLOUDINARY_URL: process.env.CLOUDINARY_URL || 'xxx',
SMTP_URL: process.env.SMTP_URL || 'xxx',
MONGODB_URL: process.env.MONGODB_URL || 'mongodb://root:[email protected]:27017/mydb',
REDIS_URL: process.env.REDIS_URL || 'redis://127.0.0.1:6379',
CLOUDINARY_URL: process.env.CLOUDINARY_URL || 'cloudinary://apikey:apisecret@cloudname',
SMTP_URL: process.env.SMTP_URL || `smtp://${user}:${pass}@smtp.ethereal.email:587`,

SECRET_KEY: process.env.SECRET_KEY || 'xxx',
SECRET_KEY: process.env.SECRET_KEY || 'jbmpHPLoaV8N0nEpuLxlpT95FYakMPiu',
}),
```

Expand Down
9 changes: 9 additions & 0 deletions src/routes/email/+handler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
import { Type } from '@sinclair/typebox';
import nunjucks from 'nunjucks';
import nodemailer from 'nodemailer';

import useMailer from '~/composables/useMailer';
import helloWorld from '~/templates/hello-world.html?raw';

export default (async (app) => {
/*
$ curl --request GET \
--url http://127.0.0.1:3000/api/email
*/
app.get(
'',
{
Expand All @@ -22,6 +27,10 @@ export default (async (app) => {
html: nunjucks.renderString(helloWorld, { hello: 'Hello, MJML!' }),
});

if (process.env.NODE_ENV === 'development') {
console.log('TestMessageUrl =', nodemailer.getTestMessageUrl(info));
}

return reply.send({ messageId: info.messageId });
},
);
Expand Down
18 changes: 14 additions & 4 deletions src/routes/file-uploads/+handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { Type } from '@sinclair/typebox';
const pipeline = util.promisify(stream.pipeline);

export default (async (app) => {
/*
$ curl --request POST \
--header "Content-Type: multipart/form-data" \
--form "image=@/Users/path/to/name.png" \
--url http://127.0.0.1:3000/api/file-uploads
*/
app.post(
'',
{
Expand All @@ -23,10 +29,14 @@ export default (async (app) => {

if (!data) return reply.badRequest();

await pipeline(
data.file,
app.cloudinary.uploader.upload_stream({ public_id: data.fieldname }),
);
if (process.env.NODE_ENV === 'production') {
await pipeline(
data.file,
app.cloudinary.uploader.upload_stream({ public_id: data.fieldname }),
);
} else {
console.log('data =', data);
}

return reply.send({ message: 'OK', url: app.cloudinary.url(data.fieldname) });
},
Expand Down
2 changes: 1 addition & 1 deletion src/shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare namespace NodeJS {
export interface ProcessEnv {
NODE_ENV: string;
NODE_ENV: 'development' | 'production';

HOST: string;
PORT: number;
Expand Down
11 changes: 5 additions & 6 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { defineConfig } from 'vite';
import fastify from 'vite-plugin-fastify';
import fastifyRoutes from 'vite-plugin-fastify-routes';
import envify from 'process-envify';
import nodemailer from 'nodemailer';

const { user, pass } = await nodemailer.createTestAccount();

export default defineConfig({
define: envify({
Expand All @@ -15,12 +18,8 @@ export default defineConfig({

MONGODB_URL: process.env.MONGODB_URL || 'mongodb://root:[email protected]:27017/mydb',
REDIS_URL: process.env.REDIS_URL || 'redis://127.0.0.1:6379',
CLOUDINARY_URL:
process.env.CLOUDINARY_URL ||
'cloudinary://636761771455612:nBBydtdox8huZPXHHsxgKFDkiUU@dfi8gex0k',
SMTP_URL:
process.env.SMTP_URL ||
'smtp://[email protected]:[email protected]:587?name=example.com',
CLOUDINARY_URL: process.env.CLOUDINARY_URL || 'cloudinary://apikey:apisecret@cloudname',
SMTP_URL: process.env.SMTP_URL || `smtp://${user}:${pass}@smtp.ethereal.email:587`,

SECRET_KEY: process.env.SECRET_KEY || 'jbmpHPLoaV8N0nEpuLxlpT95FYakMPiu',
}),
Expand Down

0 comments on commit 9cacf31

Please sign in to comment.