How to Self Host Trigger.dev V2 the Right Way
If you're looking to use https://trigger.dev/, and want to use V2 you're going to want to self host since they aren't offering new customers to the V2 cloud platform.
First create an account at https://www.doppler.com/ and create a new project called trigger-v2.
Then follow the guide on the trigger docs for how to deploy to render.com with a few adjustments.
https://trigger.dev/docs/documentation/guides/self-hosting/render
Go to https://www.uuidgenerator.net/ and get two UUIDs. In the name field paste the UUId twice. We do this because the deployed render.com instance is publicly assessible to anyone on the web. So we are going to use security by obsucation to fudge the URL as much as possible to prevent people from landing our page.
Instead of pasting the environment variables manually in render.com, add them to your doppler project and then use the integrations feature to synchronize it with your project.
Go to https://neon.tech/ to get a serverless postgres database. Use this as the database environment variable.
Create a github app and link it to your project.
Once its deployed, you can just go the deployed URL and login in with your github.
Extras: Next.js Integration
For next.js, you will probably want to integrate status hooks in your project. However the default settings won't work anymore because we are now self hosting.
Logically we will want to change the API url parameter in our TriggerProvider
. However if we just use the same render.com
url as our deployed instance, we are going to immediately lose our security by obfuscation, since anybody who lands on our web page can open the next console and see that URL.
Instead what we need is some kind of reverse proxy. We can leverage Next.js rewrites to do this.
First change your apiUrl
to /trigger-v2
Then in your next.config.js
, add a rewrites parameter with source: /trigger-v2/:api*
and destination: ${env.TRIGGER_API_URL}/:api*
respectively.
Now your trigger react hooks will get reverse proxied to your deployed render.com instance.
If you liked this article feel free to drop me a DM or email!