Next.js Discord

Discord Forum

Dynamic edge to node runtime

Answered
Catla posted this in #help-forum
Open in Discord
CatlaOP
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.
Answered by riský
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
View full answer

34 Replies

Firstly @Catla 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
Indeed my vercel node server is set to Washington.
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)
well they dont know where your server is
so they call it from one data center (i dont think they have many locations rn)
@riský well they dont know where your server is
CatlaOP
How do they know where discord users are from?
And, wouldn’t the same logic apply to edge runtime
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"
CatlaOP
Ludicrous. Spent all this time making my commands edge!
There is surely a forum or official discord post explaining this
anyway your question was having an edge which calls actual runtime for quicker initial response?
@Catla Ludicrous. Spent all this time making my commands edge! There is surely a forum or official discord post explaining this
yeah i wish it was better (it may have changed), but from my tests and so this seems accurate
and google doesnt come up with anything, i searched the ddevs server with random keywords to find again
CatlaOP
At least I get to use node modules now lol
you always would get node modules
even in edge
(as webpack bundles whats needed)
CatlaOP
I thought I read somewhere node packages didn’t work on edge
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
Answer
@Catla hi, just checking to ensure you worked it out and that its going well! (ie any questions/should thread be closed)
Indeed it's all good
Thanks for your help lad. Good day
yay thanks
@Catla Thanks for your help lad. Good day
np, i hope you enjoy the rest of your day and programming!