electerious / Ackee

Self-hosted, Node.js based analytics tool for those who care about privacy.
https://ackee.electerious.com
MIT License
4.31k stars 362 forks source link

Serverless functions and Ackee #155

Closed katriellucas closed 4 years ago

katriellucas commented 4 years ago

Is it possible to deploy and use Ackee in Vercel? One of the supported languages is Node.JS for serveless functions, I'm taking the example of Umami, also an open source analytics software which claims being able to run on vercel and netlify, interesting enough, both platforms for static aplications.

The question: is it technically possible for Ackee to do the same? I'm guessing, query the database using a serveless funtion.

I think it would be a huge step for Ackee, as this would make it a lot more acessible, anyone made an attempt on this? 🤔

electerious commented 4 years ago

I‘ve experimented a bit with serverless functions and it should be very easy to make Ackee ready for Vervel and Netlify.

We could build all static files and make them available in a /build folder (index.html, index.js, index.css, favicon.js and tracker.js). The routes are already available, we just need to add a script that runs the functions and saves the output.

The only serverless function we need is for the GraphQL requests. apollo-server-lambda should do the job.

katriellucas commented 4 years ago

Awesome!!! This is really good news, 😄👌. That would make Ackee less dependent of server-side hosting like Heroku, it would open many possibilities.

electerious commented 4 years ago

I've created an experiment, but it still needs some work: https://github.com/electerious/Ackee/tree/feature/serverless

1) I've added a build command that builds all static files into build 2) There's a Netlify config in the root of the project which still misses some environment variables 3) An api.js function in located inside functions. isAuthenticated can't handle the lambda request and needs to be adjusted (mainly because of the permit module). There's also a strange workaround in src/types/index.js. It seems that serverless functions can't load files that resolve using __dirname. Not sure why, but inlining all the GraphQL files works. Fixed that. 4) The database connection part is currently missing.

Would be great if someone could help to push this forward :)

electerious commented 4 years ago

I've managed to get Ackee up and running on Netlify 🎉

The serverless branch contains everything you need. Just add the following three environment variables and you're ready!

The first request is a bit slow, but it get's faster soon. Would be interesting to know if we can boost the performance even more.

environment

electerious commented 4 years ago

The serverless branch has been merged into develop. It will be part of the next release. Please note that the first request is a bit slow, but it get's faster soon. Would be interesting to know if we can boost the performance even more. Feedback is still welcome.