#Dynamic edge to node runtime

36 messages · Page 1 of 1 (latest)

main folio
#

Hi.

I am using next.js to run a discord bot. I accept 'interaction' requests from discord on /api/interactions (interactions refer to discord slash commands). This route is using edge runtime.

A few of my slash commands have logic that I need to use specifically in Washington D.C (Better to not ask ha). Of course, it would be bad to convert my /api/interactions in its entirety to node as that would slow down other commands.

I was thinking about creating a new route using node runtime, something like /api/interactions/node, and sending a fetch request there from /api/interactions, effectively converting the edge runtime into a node runtime.

But surely, this isn't best practice. Are there any standard procedures for this niche question, pertaining to how to potentially transfer the request from edge to node function without using fetch? Or making a new route?

Thanks.

mental stumpBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

fresh compass
#

Firstly @main folio edge runtime isnt on the edge unless you are on vercel or something which supports actual edge running

#

if you are on a nodejs server, edge runtime is like a minimal set of nodejs. Your location wont change.

#

If you are on something which supports location changing, yes the /node is probs the best idea here

main folio
#

Indeed my vercel node server is set to Washington.

lavish zealot
#

for discord http interaction bot, yeah you dont want edge as discord only has one place (i forgot which place they call it from but there sounds right/close)

main folio
lavish zealot
#

well they dont know where your server is

#

so they call it from one data center (i dont think they have many locations rn)

main folio
#

And, wouldn’t the same logic apply to edge runtime

lavish zealot
#

no matter where the discord user requests, it sends to the discord server which then calls you

#

apparently it seems like everything with api has to get sent to the "central server in US East"

main folio
#

Ludicrous. Spent all this time making my commands edge!
There is surely a forum or official discord post explaining this

lavish zealot
#

anyway your question was having an edge which calls actual runtime for quicker initial response?

lavish zealot
#

and google doesnt come up with anything, i searched the ddevs server with random keywords to find again

main folio
#

At least I get to use node modules now lol

lavish zealot
#

you always would get node modules

#

even in edge

#

(as webpack bundles whats needed)

main folio
#

I thought I read somewhere node packages didn’t work on edge

lavish zealot
#

like if it uses node specific parts

#

ie node:crypto

#

but edge will always be better cold start

#

vercel serverless will last up to 60sec now however :)

#

btw i found another thing saying they can be in other places, but doesnt sound very likely and even if it does its still going to be fast

lavish zealot
#

@main folio hi, just checking to ensure you worked it out and that its going well! (ie any questions/should thread be closed)

main folio
#

Indeed it's all good

#

Thanks for your help lad. Good day

lavish zealot
#

yay thanks

mental stumpBOT
#
✅ Success!

This question has been marked as answered! If you have any other questions, feel free to create another post

Jump to answer

[Click here](#1239142009009213502 message)