zodern / mup-aws-beanstalk

Deploy Meteor apps to AWS Elastic Beanstalk using Meteor Up
127 stars 56 forks source link

aws-health-check route #169

Closed ddaydd closed 2 years ago

ddaydd commented 2 years ago

hello I manage my 404 errors this way.

const { pathToRegexp } = require("path-to-regexp");

Meteor.startup(() => {
  // Return a 404 HTTP response if the route doesn't exist
  WebApp.connectHandlers.use("/", function (req, res, next) {
    let paths = _.uniq(Router.routes.map((route) => route._path));
    paths.push("/reset-password/:token");
    if (req.url.slice(0, 17) === '/aws-health-check') next();
    else {
      let mainUrl = req.url.split('?')[0];
      if (_.find(paths, (path) => pathToRegexp(path).test(mainUrl))) next();
      else {
        dfm.logError({ messages: [`404: ${req.url}`], tag: "404" });
        res.writeHead(404, { 'Content-Type': 'text/html' });

        const contents = Assets.getText('404.html');
        res.end(contents);
      }
    }
  });
});

If I don't add the line that allows the "/aws-health-check" route, the deployment fails, is that normal?

zodern commented 2 years ago

I released version 0.8.0 yesterday which should fix it. Have you tried the new version?

ddaydd commented 2 years ago

Ah, ok, not tried yet, I will. thank you

ddaydd commented 2 years ago

I just tried it, it's good. thank you