browser-calls-node icon indicating copy to clipboard operation
browser-calls-node copied to clipboard

Basic example of browser calls.

Open zawarski opened this issue 4 years ago • 1 comments

Possible to create an example with only what is required to make a browser call (without all the mongo and other stuff)?

zawarski avatar Apr 17 '21 16:04 zawarski

To eliminate the MongoDB requirement, as a hacky fix, you can edit this line of bin/www to change it to:

const { MongoMemoryServer } = require('mongodb-memory-server');

const mongod = new MongoMemoryServer();

const mongooseOpts = {
  useNewUrlParser: true,
  useUnifiedTopology: true
};

(async () => await mongoose.connect(await mongod.getConnectionString(), mongooseOpts))();

This seems to work for me.

You'll notice that this lets the server start possibly before the database is initialized. This is an issue with the existing code: It doesn't await the DB start, but it likely won't be an issue in testing.

This code is pretty much copied from the unit test, so it seems like a 5-minute task to make a config option to use an in-memory DB.

Overall, the demo looks really nice and fancy, but it would be far easier to understand a quick demo than a more involved one like this with application logic on top of it. Just a simple HTML page with no CSS would do.

KB1RD avatar May 04 '21 00:05 KB1RD