Walshy | Pages
02/26/2023, 7:12 PMhttps://user-images.githubusercontent.com/40433209/192508289-425b8006-eb7c-498b-a742-7403ca77b7bc.png▾
ajgeiss0702
02/26/2023, 7:29 PMSuchACharles
02/26/2023, 11:41 PMjs
import type { NextRequest } from 'next/server'
export const config = {
runtime: 'edge',
}
export default async function handler(
req: NextRequest,
env: any
): Promise<Response> {
const ps = env.MY_DB.prepare('SHOW TABLES')
const data = await ps.first()
return new Response(
JSON.stringify({
message: 'Hello World!',
data: data,
}),
{
status: 200,
headers: {
'Content-Type': 'application/json',
},
}
)
}
vedmant
02/27/2023, 1:57 AMjs
const resp = await fetch('https://api.mailchannels.net/tx/v1/send', {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
personalizations: [
{
to: [{ email: 'info@bla.com', name: 'bla' }],
},
],
from: {
email: 'no-reply@bla.com',
name: 'bla contact form',
},
subject: 'bla.com contact form',
content: [
{
type: 'text/plain',
value: `Name: ${output.name}\n Email: ${output.email}\n Message: ${output.message}`,
},
],
}),
})e
And it doesn't work, returns: 401 Authorization Required
So what's proper way of sending emails via functions?
I have AWS SES configured, but I can't send SMTP, also looks like I can't use aws-sdk
vedmant
02/27/2023, 2:37 AMPause
02/27/2023, 3:40 AMPause
02/27/2023, 4:11 AMHardAtWork
02/27/2023, 8:21 AMrage5quid
02/27/2023, 10:09 AMHardAtWork
02/27/2023, 10:16 AMwrangler
won't automatically include the Pages router for your functions. It should still bundle your _worker.ts
file.rage5quid
02/27/2023, 10:19 AM_worker.js
file from my _worker.ts
file. Or is this something that still has to be implemented in the wranger pages dev
module? Or is there a way to make wrangler generate the js file locally?rage5quid
02/27/2023, 10:20 AMHardAtWork
02/27/2023, 10:20 AMrage5quid
02/27/2023, 10:22 AMwrangler pages dev
? When the _worker.js file does not exist?HardAtWork
02/27/2023, 10:24 AMesbuild
) has a function that allows it to build directly to an object in memory, allowing it to run faster, because it doesn't have to write to a worker.js
file, and then immediately read it again.rage5quid
02/27/2023, 10:26 AMrage5quid
02/27/2023, 10:28 AMHardAtWork
02/27/2023, 10:29 AMrage5quid
02/27/2023, 10:33 AMsrc
folder with a _worker.ts
with a fetch handler. Together with a simple tsconfig.json with the workers-types. If I run wranger pages dev src
the worker does not run, all I get is 404's. When I compile the _worker.ts to _worker.js using tsc then it works as expected. So the transpilation does not happen automatically. Or did you mean that I have to manage the esbuild myself?HardAtWork
02/27/2023, 10:35 AMHardAtWork
02/27/2023, 10:35 AMrage5quid
02/27/2023, 10:36 AMrage5quid
02/27/2023, 10:37 AMHardAtWork
02/27/2023, 10:38 AMesbuild _worker.ts --bundle --minify --target=esnext --format=esm --outfile=_worker.js
, but I can try to dig out the "official" one for you...rage5quid
02/27/2023, 10:38 AMHardAtWork
02/27/2023, 10:41 AMwrangler
source is pretty complex, but the above has always worked for me.Larry
02/27/2023, 1:10 PMBetter James
02/27/2023, 4:15 PMCannot redefine property: ...
, because each function route is requiring another file that defines the same property on globalThis.
My understanding of functions is that each file is its own thing, i.e. my function routes shouldn't be sharing logic between the two of them.
Is there a way to not have wrangler compile all pages functions into the same file? I thought you were supposed to be able to use different files for different routes.kian
02/27/2023, 4:23 PMkian
02/27/2023, 4:23 PMglobalThis
?