core
core copied to clipboard
Workers support to use SSL for SaaS
Is your feature request related to a problem? Please describe. SSL for SaaS is not compatible with Cloudflare Pages, which is a blocker to doing SaaS with custom user domains on Nuxt Hub.
Describe the solution you'd like The ability to deploy Nuxt Hub apps using module format Workers instead of Pages.
Describe alternatives you've considered
The only workaround I'm aware of is setting up a Worker for the fallback origin which proxies requests to Pages, however I'm getting D1_TYPE_ERROR when using D1 in API routes on the proxy. The only workaround I've found there is directly hitting the API routes on the domain which is assigned to Pages, which isn't ideal.
If I understand properly @timhanlon, you want the ability to set multiple custom domain for a project?
On Pages, I can do this and the customer only have to set the CNAME on his DNS (expect for APEX).
I am happy to better understand what you are building to better serve your purpose!
Ah, I wasn't aware that external domains on Pages was an option.
Couple of things:
- This requires the customer to CNAME to mysaas.pages.dev rather than customers.mysaas.com
- SSL for SaaS is $0.10 per domain once you've reached 100 domains, which is much less expensive & restrictive than Pages custom domain limits
I'm also having the same issue ATM.
Now having to change my entire plan, and have to move with this https://developers.cloudflare.com/workers/frameworks/framework-guides/nuxt/ instead of using NuxtHub for customer facing part.
I think it should be the top priority as per the situation of pages vs worker.
@Ain477 Here's the workaround I'm using at the moment, in case it helps. It's a self-hosted setup and it loses the CI/CD, but I can use all the Nuxt Hub primitives in a Nuxt app on Workers and have a customers.[app].com origin for customers to CNAME to. The only issue I had was working around the difference in how Workers/Pages handles env variables. Using pnpm patch to patch @nuxthub/core:
diff --git a/dist/runtime/utils/auth.js b/dist/runtime/utils/auth.js
index 264bc31aea16856265594c29fdce9269aff72841..938a235011ec72c7fc7d719de333ca367e386063 100644
--- a/dist/runtime/utils/auth.js
+++ b/dist/runtime/utils/auth.js
@@ -1,5 +1,6 @@
import { getHeader, createError } from "h3";
import { $fetch } from "ofetch";
+import { useRuntimeConfig } from "#imports";
const localCache = /* @__PURE__ */ new Map();
export async function requireNuxtHubAuthorization(event) {
if (import.meta.dev) {
@@ -14,7 +15,7 @@ export async function requireNuxtHubAuthorization(event) {
}
const env = event.context.cloudflare?.env || process.env || {};
const projectKey = env.NUXT_HUB_PROJECT_KEY;
- const projectSecretKey = env.NUXT_HUB_PROJECT_SECRET_KEY;
+ const projectSecretKey = useRuntimeConfig(event).hub?.projectSecretKey;
if (projectSecretKey && secretKeyOrUserToken === projectSecretKey) {
return;
} else if (projectSecretKey && !projectKey) {
NuxtHub now supports deploying to Cloudflare Workers 😃 https://hub.nuxt.com/changelog/workers
If you run into any issues from NuxtHub when trying using Cloudflare for SaaS with Workers projects, do let me know and I can reopen the issue and investigate.