Code Monkey home page Code Monkey logo

Comments (8)

slimee avatar slimee commented on June 18, 2024 6

Hi guys,

Happy to say you that (later is better than never) this will be handled in v6.
Liana.init will return a promise that resolves after complete initialization.

from forest-express.

louisremi avatar louisremi commented on June 18, 2024 1

At Mon Bel Appart, we've found a reliable way to detect when the Liana has successfully initialized by hijacking different functions of its API. Here's how we've done it: https://github.com/monbelappart/monbelappart/blob/master/src/utils/Forest/hijackLiana.ts

from forest-express.

arnaudbesnier avatar arnaudbesnier commented on June 18, 2024 1

@atwoodjw @pangolingo @louisremi @davidbillamboz @tlubz thank you for your patience guys.
This contribution is available in a new 6.0.0-beta.0 beta version.

As a new premajor version, it contains breaking changes, so please take the time to read the upgrade note and test all your changes in a development environment before moving it to upper stages (staging, production,...)

🌲🌲🌲

from forest-express.

tlubz avatar tlubz commented on June 18, 2024

We have been seeing the same issue in our implementation. Serverless/lambda really seems like the way to go for hosting these liana nanoservices. We are using forest-express-sequelize (through lumber-cli). Having a persistent server to proxy light admin traffic to a postgres database seems like overkill.

We have been forced to use a pretty clumsy workaround here, and wrap our AwsServerlessExpress.proxy(...) call in a setTimeout(..., 200) block.

It would be great if the ForestExpress.init call set a promise on the returned object, or returned a promise, as the app returned is essentially not usable until the readdirAsync promise chain settles.

Alternatively, exposing a "ready" callback in the opts could be useful (e.g. similar to #181).

from forest-express.

Ni0rd avatar Ni0rd commented on June 18, 2024

Hi,
I am also experiencing this.
I fixed it by disabling the auto schema sync : FOREST_DISABLE_AUTO_SCHEMA_APPLY = true and also by implementing a very dirty hack to detect when the last request is made... here an exemple in TypeScript for Zeit Now.

import EventEmitter from 'events';
import forestExpressSequelize from 'forest-express-sequelize';
import forestExpressServiceIpWhitelist from 'forest-express/dist/services/ip-whitelist';
import { sequelize } from '../sequelize';

const app = forestExpressSequelize.init({
  envSecret: process.env.FOREST_ENV_SECRET,
  authSecret: process.env.FOREST_AUTH_SECRET,
  sequelize,
});

const emitter = new EventEmitter();

let ipWhitelistDone = false;

const old = forestExpressServiceIpWhitelist.retrieve;
forestExpressServiceIpWhitelist.retrieve = async (
  environmentSecret,
): Promise<void> => {
  await old(environmentSecret);
  ipWhitelistDone = true;
  emitter.emit('ipWhitelistReady');
};

function ipWhitelistReady(): Promise<void> {
  return new Promise((resolve): void => {
    if (ipWhitelistDone) {
      resolve();
      return;
    }
    emitter.on('ipWhitelistReady', resolve);
  });
}

app.use(async (req, res, next) => {
  await ipWhitelistReady();
  next();
});

export default app;

from forest-express.

pangolingo avatar pangolingo commented on June 18, 2024

We're still seeing this issue since @atwoodjw reported it last year. As he said, the problem is that we’re running on AWS Lambda and the Forest library doesn’t have time to boot before it tries to handle the request. This causes intermittent 404 errors because sometimes a new Lambda is spun up and sometimes an existing Lambda is reused (when reusing a Lambda the library has been initialized and responds successfully).

We need a way to await the library initialization before asking it to handle the request.

from forest-express.

p0wl avatar p0wl commented on June 18, 2024

I want to use forest admin within aws lambda, but I cannot manage to add a production connection using the dashboard, I'm stuck in the "Set your environment variables" step. I tried debugging it, but I don't get any log output from forest or anything else. All I see is that the calss to /forest are answered with http 204 without any response.

I tried to use aws-serverless-express to wrap forest-admin in a lambda function, my entrypoint looks like this:

'use strict';

const awsServerlessExpress = require('aws-serverless-express');
const app = require('./app');
const server = awsServerlessExpress.createServer(app);

exports.handler = (event, context) => { awsServerlessExpress.proxy(server, event, context) };

and I have not changed app.js or anything else.

The serverless.yml is pretty simple as well:

service: myservice

provider:
  name: aws
  runtime: nodejs12.x
  stage: production
  region: eu-central-1

package:
  exclude:
    - '.env'

functions:
  forestadmin:
    handler: serverless.handler
    events:
      - httpApi: '*'
        cors: true
    environment:
      FOREST_ENV_SECRET: '...'
      FOREST_AUTH_SECRET: '...'
      FOREST_DISABLE_AUTO_SCHEMA_APPLY: true
      DATABASE_URL: 'postgres://...'
      DATABASE_SCHEMA: public
      DATABASE_SSL: false
      NODE_ENV: production

from forest-express.

arnaudbesnier avatar arnaudbesnier commented on June 18, 2024

Hi @p0wl, I am not sure to understand how this is related to the issue.
If you need help to configure your aws lambda maybe you should ask for help here or create a dedicated issue.

from forest-express.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.