Greenlock with Angular Universal #43

Closed
opened 2019-08-09 05:09:00 +00:00 by Ghost · 13 comments

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 of require (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

var path = require('path');
var os = require('os')
var Greenlock = require('greenlock');
var GreenlockExpress = require('greenlock-express')

var greenlock = GreenlockExpress.create({
    version: 'draft-12',
    email: 'brayden@madebybuilt.com',
    agreeTos: true,
    server: 'https://acme-v02.api.letsencrypt.org/directory',
    approveDomains: [ 'traveling-canvas.com', 'www.traveling-canvas.com' ],
    app: require("./dist/server.js"),

    // If you wish to replace the default account and domain key storage plugin
    store: require('le-store-fs').create({
        configDir: path.join(os.homedir(), 'acme/etc'),
        webrootPath: '/tmp/acme-challenges'
    })
});


/////////////////////
// APPROVE DOMAINS //
/////////////////////

var http01 = require('le-challenge-fs').create({ webrootPath: '/tmp/acme-challenges' });
function approveDomains(opts, certs, cb) {
    opts.communityMember = true;
    opts.challenges = { 'http-01': http01 };
    opts.email = 'brayden@madebybuilt.com';
    opts.agreeTos = true;

    cb(null, { options: opts, certs: certs });
}


////////////////////
// CREATE SERVERS //
////////////////////


greenlock.listen(80, 443);

Server.ts

'use strict';

// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-metadata';

import { enableProdMode } from '@angular/core';

import * as express from 'express';
import { join } from 'path';


// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();

// Express server
const app = express();

const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist');

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main');

// Express Engine
import { ngExpressEngine } from '@nguniversal/express-engine';
// Import module map for lazy loading
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';

app.engine('html', ngExpressEngine({
  bootstrap: AppServerModuleNgFactory,
  providers: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
}));

app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));

// app.use(function(req, res, next) {
//     if((!req.secure) && (req.get('X-Forwarded-Proto') !== 'https')) {
//         res.redirect('https://' + req.get('Host') + req.url);
//     }
//     else
//         next();
// });

// app.use('/', function (req, res) {
//     res.setHeader('Content-Type', 'text/html; charset=utf-8');
//     res.end('Hello, World!');
// })

// TODO: implement data requests securely
app.get('/api/*', (req, res) => {
  res.status(404).send('data requests are not supported');
});

// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));

// All regular routes use the Universal engine
app.get('*', (req, res) => {
  res.render('index', { req });
});

module.exports = app;

Any help would be so appreciated. I've been hung up on this for three straight nights...

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 of `require` (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 ``` var path = require('path'); var os = require('os') var Greenlock = require('greenlock'); var GreenlockExpress = require('greenlock-express') var greenlock = GreenlockExpress.create({ version: 'draft-12', email: 'brayden@madebybuilt.com', agreeTos: true, server: 'https://acme-v02.api.letsencrypt.org/directory', approveDomains: [ 'traveling-canvas.com', 'www.traveling-canvas.com' ], app: require("./dist/server.js"), // If you wish to replace the default account and domain key storage plugin store: require('le-store-fs').create({ configDir: path.join(os.homedir(), 'acme/etc'), webrootPath: '/tmp/acme-challenges' }) }); ///////////////////// // APPROVE DOMAINS // ///////////////////// var http01 = require('le-challenge-fs').create({ webrootPath: '/tmp/acme-challenges' }); function approveDomains(opts, certs, cb) { opts.communityMember = true; opts.challenges = { 'http-01': http01 }; opts.email = 'brayden@madebybuilt.com'; opts.agreeTos = true; cb(null, { options: opts, certs: certs }); } //////////////////// // CREATE SERVERS // //////////////////// greenlock.listen(80, 443); ``` Server.ts ``` 'use strict'; // These are important and needed before anything else import 'zone.js/dist/zone-node'; import 'reflect-metadata'; import { enableProdMode } from '@angular/core'; import * as express from 'express'; import { join } from 'path'; // Faster server renders w/ Prod mode (dev mode never needed) enableProdMode(); // Express server const app = express(); const PORT = process.env.PORT || 4000; const DIST_FOLDER = join(process.cwd(), 'dist'); // * NOTE :: leave this as require() since this file is built Dynamically from webpack const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main'); // Express Engine import { ngExpressEngine } from '@nguniversal/express-engine'; // Import module map for lazy loading import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader'; app.engine('html', ngExpressEngine({ bootstrap: AppServerModuleNgFactory, providers: [ provideModuleMap(LAZY_MODULE_MAP) ] })); app.set('view engine', 'html'); app.set('views', join(DIST_FOLDER, 'browser')); // app.use(function(req, res, next) { // if((!req.secure) && (req.get('X-Forwarded-Proto') !== 'https')) { // res.redirect('https://' + req.get('Host') + req.url); // } // else // next(); // }); // app.use('/', function (req, res) { // res.setHeader('Content-Type', 'text/html; charset=utf-8'); // res.end('Hello, World!'); // }) // TODO: implement data requests securely app.get('/api/*', (req, res) => { res.status(404).send('data requests are not supported'); }); // Server static files from /browser app.get('*.*', express.static(join(DIST_FOLDER, 'browser'))); // All regular routes use the Universal engine app.get('*', (req, res) => { res.render('index', { req }); }); module.exports = app; ``` Any help would be so appreciated. I've been hung up on this for three straight nights...
Owner

I don't know the first thing about TypeScript or Angular-non-js.

What's the error that you get?

I don't know the first thing about TypeScript or Angular-non-js. What's the error that you get?
Author

@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.

/home/ec2-user/built.web/server.ts:64
import 'zone.js/dist/zone-node';
       ^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected string
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:656:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/home/ec2-user/built.web/greenlock.js:146:10)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)

I can't be the first person to try to use Greenlock with Angular Universal can I? 👀

@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. ``` /home/ec2-user/built.web/server.ts:64 import 'zone.js/dist/zone-node'; ^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Unexpected string at new Script (vm.js:79:7) at createScript (vm.js:251:10) at Object.runInThisContext (vm.js:303:10) at Module._compile (internal/modules/cjs/loader.js:656:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32) at tryModuleLoad (internal/modules/cjs/loader.js:537:12) at Function.Module._load (internal/modules/cjs/loader.js:529:3) at Module.require (internal/modules/cjs/loader.js:636:17) at require (internal/modules/cjs/helpers.js:20:18) at Object.<anonymous> (/home/ec2-user/built.web/greenlock.js:146:10) at Module._compile (internal/modules/cjs/loader.js:688:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32) at tryModuleLoad (internal/modules/cjs/loader.js:537:12) at Function.Module._load (internal/modules/cjs/loader.js:529:3) ``` I can't be the first person to try to use Greenlock with Angular Universal can I? :eyes:
Owner

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?

import * as GreenlockExpress from 'greenlock-express';

Or run node with the mjs options?

https://stackoverflow.com/a/45854500/151312

Or do any of this?

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? ```ts import * as GreenlockExpress from 'greenlock-express'; ``` Or run node with the `mjs` options? <https://stackoverflow.com/a/45854500/151312> Or do any of this? * <https://www.techiediaries.com/use-external-javascript-libraries-typescript-projects/> * <https://www.thepolyglotdeveloper.com/2016/01/include-external-javascript-libraries-in-an-angular-2-typescript-project/>
Owner

Was any of that helpful?

Was any of that helpful?
Author

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?

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?
Author

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:

Fetching certificate for 'traveling-canvas.com' to use as default for HTTPS server...
Error loading/registering certificate for 'traveling-canvas.com':
TypeError: Cannot set property 'hexToBuf' of undefined
    at Object.<anonymous> (/home/ec2-user/built.web/node_modules/cert-info/lib/cert-info.js:13:14)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/home/ec2-user/built.web/node_modules/cert-info/index.js:7:18)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)

Unhandled rejection TypeError: Cannot set property 'hexToBuf' of undefined
    at Object.<anonymous> (/home/ec2-user/built.web/node_modules/cert-info/lib/cert-info.js:13:14)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/home/ec2-user/built.web/node_modules/cert-info/index.js:7:18)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)

Edited error response

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: ``` Fetching certificate for 'traveling-canvas.com' to use as default for HTTPS server... Error loading/registering certificate for 'traveling-canvas.com': TypeError: Cannot set property 'hexToBuf' of undefined at Object.<anonymous> (/home/ec2-user/built.web/node_modules/cert-info/lib/cert-info.js:13:14) at Module._compile (internal/modules/cjs/loader.js:688:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32) at tryModuleLoad (internal/modules/cjs/loader.js:537:12) at Function.Module._load (internal/modules/cjs/loader.js:529:3) at Module.require (internal/modules/cjs/loader.js:636:17) at require (internal/modules/cjs/helpers.js:20:18) at Object.<anonymous> (/home/ec2-user/built.web/node_modules/cert-info/index.js:7:18) at Module._compile (internal/modules/cjs/loader.js:688:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32) at tryModuleLoad (internal/modules/cjs/loader.js:537:12) at Function.Module._load (internal/modules/cjs/loader.js:529:3) at Module.require (internal/modules/cjs/loader.js:636:17) at require (internal/modules/cjs/helpers.js:20:18) Unhandled rejection TypeError: Cannot set property 'hexToBuf' of undefined at Object.<anonymous> (/home/ec2-user/built.web/node_modules/cert-info/lib/cert-info.js:13:14) at Module._compile (internal/modules/cjs/loader.js:688:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32) at tryModuleLoad (internal/modules/cjs/loader.js:537:12) at Function.Module._load (internal/modules/cjs/loader.js:529:3) at Module.require (internal/modules/cjs/loader.js:636:17) at require (internal/modules/cjs/helpers.js:20:18) at Object.<anonymous> (/home/ec2-user/built.web/node_modules/cert-info/index.js:7:18) at Module._compile (internal/modules/cjs/loader.js:688:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10) at Module.load (internal/modules/cjs/loader.js:598:32) at tryModuleLoad (internal/modules/cjs/loader.js:537:12) at Function.Module._load (internal/modules/cjs/loader.js:529:3) at Module.require (internal/modules/cjs/loader.js:636:17) at require (internal/modules/cjs/helpers.js:20:18) ``` Edited error response
Owner
   server: 'https://acme-v02.api.letsencrypt.org/directory',

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.

Unhandled rejection TypeError: Cannot set property 'hexToBuf' of undefined

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.

``` server: 'https://acme-v02.api.letsencrypt.org/directory', ``` 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. > Unhandled rejection TypeError: Cannot set property 'hexToBuf' of undefined 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.
Author

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).

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. :sweat_smile: 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).
Owner

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.

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.
Author

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):

var greenlock = GreenlockExpress.create({
    version: 'draft-12',
    email: 'brayden@madebybuilt.com',
    agreeTos: true,
    server: 'https://acme-staging-v02.api.letsencrypt.org/directory',
    approveDomains: [ 'traveling-canvas.com', 'www.traveling-canvas.com' ],

    // If you wish to replace the default account and domain key storage plugin
    store: require('le-store-fs').create({
        configDir: path.join(os.homedir(), 'acme/etc'),
        webrootPath: '/tmp/acme-challenges'
    })
});

var redir = require('redirect-https')();
require('http').createServer(greenlock.middleware(redir)).listen(80);

require('https').createServer(greenlock.tlsOptions, function (req, res) {
    res.end('Hello, Secure World!');
}).listen(443);

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.

var greenlock = GreenlockExpress.create({
    version: 'draft-12',
    email: 'brayden@madebybuilt.com',
    agreeTos: true,
    server: 'https://acme-staging-v02.api.letsencrypt.org/directory',
    approveDomains: [ 'traveling-canvas.com', 'www.traveling-canvas.com' ],
    app: require("./dist/server.js"),

    // If you wish to replace the default account and domain key storage plugin
    store: require('le-store-fs').create({
        configDir: path.join(os.homedir(), 'acme/etc'),
        webrootPath: '/tmp/acme-challenges'
    })
});

greenlock.listen(80, 443);

This may just be regurgitating information but trying to help out as much as possible in providing everything I can.

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): ``` var greenlock = GreenlockExpress.create({ version: 'draft-12', email: 'brayden@madebybuilt.com', agreeTos: true, server: 'https://acme-staging-v02.api.letsencrypt.org/directory', approveDomains: [ 'traveling-canvas.com', 'www.traveling-canvas.com' ], // If you wish to replace the default account and domain key storage plugin store: require('le-store-fs').create({ configDir: path.join(os.homedir(), 'acme/etc'), webrootPath: '/tmp/acme-challenges' }) }); var redir = require('redirect-https')(); require('http').createServer(greenlock.middleware(redir)).listen(80); require('https').createServer(greenlock.tlsOptions, function (req, res) { res.end('Hello, Secure World!'); }).listen(443); ``` 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. ``` var greenlock = GreenlockExpress.create({ version: 'draft-12', email: 'brayden@madebybuilt.com', agreeTos: true, server: 'https://acme-staging-v02.api.letsencrypt.org/directory', approveDomains: [ 'traveling-canvas.com', 'www.traveling-canvas.com' ], app: require("./dist/server.js"), // If you wish to replace the default account and domain key storage plugin store: require('le-store-fs').create({ configDir: path.join(os.homedir(), 'acme/etc'), webrootPath: '/tmp/acme-challenges' }) }); greenlock.listen(80, 443); ``` This may just be regurgitating information but trying to help out as much as possible in providing everything I can.
Owner

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:

function (req, res) {
  // ...
}

Chainable middleware functions (express or not) have this function signature:

function (req, res, next) {
  // ...
}

What happens if you do this?

var greenlock = GreenlockExpress.create({
    // ...
    app: function (req, res) {
        console.log(req.url);
        var myapp = require("./dist/server.js");
        console.log(myapp.toString());
        myapp(req, res);
    }
    // ...
});

My guess is that you're exporting something from ./dist/server.js that isn't an express app, nor an http function.

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: ```js function (req, res) { // ... } ``` Chainable middleware functions (express or not) have this function signature: ```js function (req, res, next) { // ... } ``` What happens if you do this? ```js var greenlock = GreenlockExpress.create({ // ... app: function (req, res) { console.log(req.url); var myapp = require("./dist/server.js"); console.log(myapp.toString()); myapp(req, res); } // ... }); ``` My guess is that you're exporting something from `./dist/server.js` that _isn't_ an express app, nor an http function.
Author

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?

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?
Owner

Typically express middleware have some sort of create function.

For example:

var createParseJson = require('body-parser').json;
var parseJson = createParseJson();
app.use('/api', parseJson);

If you call the create function within a request, you will re-initialize that middle ware each time:

For example:

var createParseJson = require('body-parser').json;
app.post('/api/thing', function (req, res, next) {
  var parseJson = createParseJson();
  parseJson(req, res);
  next();
});

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.

Typically express middleware have some sort of create function. For example: ```js var createParseJson = require('body-parser').json; var parseJson = createParseJson(); app.use('/api', parseJson); ``` If you call the create function within a request, you will re-initialize that middle ware each time: For example: ```js var createParseJson = require('body-parser').json; app.post('/api/thing', function (req, res, next) { var parseJson = createParseJson(); parseJson(req, res); next(); }); ``` 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.
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: coolaj86/greenlock.js-ARCHIVED#43
No description provided.