Skip to content

Workers support to use SSL for SaaS #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
timhanlon opened this issue Sep 7, 2024 · 4 comments
Open

Workers support to use SSL for SaaS #267

timhanlon opened this issue Sep 7, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@timhanlon
Copy link

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.

@atinux atinux added the enhancement New feature or request label Sep 9, 2024
@atinux
Copy link
Contributor

atinux commented Sep 9, 2024

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!

@timhanlon
Copy link
Author

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

@Ain477
Copy link

Ain477 commented Dec 2, 2024

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.

@timhanlon
Copy link
Author

@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) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants