Greenlock with Angular Universal #43
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I have been able to successfully get Greenlock setup if I'm attempting to do a basic response of an HTML string as the server page body.
However.... I am trying to deploy an Angular Universal project that wraps itself in an Express app. However, due to some ES6 requirements and how Angular wraps this with
import
instead ofrequire
(and seems to still have problems if I convert that with other things) there doesn't seem to be a good way to handle this.Below are the pieces of code for controlling (1) Greenlock initiation, and (2) the
server.ts
file that Angular Universal outputs.Greenlock.js
Server.ts
Any help would be so appreciated. I've been hung up on this for three straight nights...
I don't know the first thing about TypeScript or Angular-non-js.
What's the error that you get?
@coolaj86 - Thanks so much first and foremost for creating this and also spending time on super helpful videos. You're a rockstar.
Here's the error I'm getting.
I can't be the first person to try to use Greenlock with Angular Universal can I? 👀
You're welcome. I'll be launching a campaign on IndieGoGo to get the next version out on time, before the Let's Encrypt breaking change, and I'd greatly appreciate your support in that.
Can you invert what you're trying to do?
Or run node with the
mjs
options?https://stackoverflow.com/a/45854500/151312
Or do any of this?
Was any of that helpful?
So I've been trying to find a way to make some of that applicable but have been falling short. This may be a stretch of an ask here, but would you be willing to take a look at my setup over a Google Hangout or any other means?
I feel like we're on the cusp of success but missing one piece somewhere.
Side note: Would love to help with the IndieGoGo. Is there a link to be notified when it comes live?
This is where I'm currently stuck at the moment with my current train of thought. I updated the Angular Universal build script to conform to ES6, removed my
acme/etc
folder to clear out all certs and this is the error I am currently seeing:Edited error response
Hmmm... you should probably use the staging API rather than the production API while you debug. You may hit your rate limits and not be able to get a certificate.
You are getting very strange errors. It looks almost as if it's trying to compile node code using browser APIs... does that ring a bell?
I'm strictly a JavaScript guy and although I probably have enough experience to guide you a little bit, I'm not expert in TypeScrypt or BabelScript at all. I stay away from them because I find that they add a lot of complexity, bloat code size, and make things much more difficult to debug.
However, I'm going to tag a buddy of mine who's into TypeScript and BabelScript and see if he's got any ideas.
Sure, any help works. I'll pay whoever gets it running for me! This is the last hurdle stopping me from launching my SaaS platform. 😅
And with Angular Universal it does create a
server.ts
file that is node code but bootstraps a browser/FE project from a single page application (SPA).Greenlock can't (and shouldn't) be compiled from the node version into a browser version. If you had wanted to run it in the browser, there is a browser version, but I don't think that's what you're trying to do.
My buddy took a look over and sent a few comments, but has no idea. I have another person in mind that I'll try.
I'm running both Greenlock and Angular Universal as a node project actually.
Not sure if this adds anything helpful to the case but here is a situation where it does render a successful certificate on the address bar but only outputs an HTML string (as expected):
Compared to this, where I add in the
app
key/value to my Greenlock instance and it doesn't render anything in the browser at all, and doesn't add any certificate notification in the address bar either.This may just be regurgitating information but trying to help out as much as possible in providing everything I can.
That sounds like you're passing the wrong type of function as the express app (it receives the arguments, does nothing useful with them, and never calls
res.send()
).Are you sure that
require("./dist/server.js")
is returning an express object?Any http app in node (express or not) has this function signature:
Chainable middleware functions (express or not) have this function signature:
What happens if you do this?
My guess is that you're exporting something from
./dist/server.js
that isn't an express app, nor an http function.So progress has been made! Thanks for helping point me in the right direction @coolaj86 I had tried that once before and received a slew of various other errors but turns out those errors were due to Angular Universals compiled code.
As it turns out to make it work properly with Angular there were other file that needed modified after the Universal application was compiled (what files are actually ran on the server). The downside right now seems like every request may be restarting the Express application that Angular Universal produces and I'll have to look into that... but for the time being the website is being rendered successfully:
https://traveling-canvas.com
I take it you haven't seen any issues where the Express app used via Greenlock would restart it each time a new request comes through?
Typically express middleware have some sort of create function.
For example:
If you call the create function within a request, you will re-initialize that middle ware each time:
For example:
I'm going to go ahead and close this out since the problem is definitely not anything with Greenlock, but we can continue the discussion.