appy-one / acebase-server

A fast, low memory, transactional, index & query enabled NoSQL database server for node.js that easily syncs with browser and node.js clients and servers
MIT License
32 stars 14 forks source link

Attach to an existing server #49

Closed Azarattum closed 1 year ago

Azarattum commented 1 year ago

Let's say we already have a node http server instance running. It would be nice to be able to attach acebase to that server and specify a route it will use. For example it might look like this:

import { AceBaseServer } from "acebase-server";
import { createServer } from "http";

const server = createServer();
server.listen(8080);

/* Our own server logic... */

new AceBaseServer("mydb", { server, prefix: "/acebase" });
// Attach acebase at http://localhost:8080/acebase

If there are workarounds currently that allow to attach AceBase to an existing server, please let me know. I know that there is a .app that lets you access the express app underneath, but in my use case the server is created before the AceBase is initialized, so I cannot use its http instance... Therefore, .extend also doesn't work for me...

One more thing is that new AceBaseServer automatically starts listening which is not ideal. I think it would make sense that if you pass the server param, the said server will control when it will start to listen (as well as its port).

appy-one commented 1 year ago

Thanks @Azarattum, I'll take a look at implementing this. Feel free to drop a PR if you'd like to contribute!

Azarattum commented 1 year ago

@appy-one, take a look at https://github.com/appy-one/acebase-server/pull/55

appy-one commented 1 year ago

Closed by merging #55, many thanks @Azarattum!

Spread the word contribute Sponsor AceBase