@musare/musare v2.1.1
MusareNode
Based off of the original Musare, which utilized Meteor.
MusareNode now uses NodeJS, Express, SocketIO and VueJS - among other technologies. We have also implemented the ability to host Musare in Docker Containers.
The master branch is available at musare.com You can also find the staging branch at musare.dev
Contact
Get in touch with us via email at core@musare.com or join our Discord Guild.
You can also find us on Facebook and Twitter.
Our Stack
- NodeJS
- MongoDB
- Redis
- Nginx (not required)
- VueJS
Frontend
The frontend is a vue-cli generated, vue-loader single page app, that's served over Nginx or Express. The Nginx server not only serves the frontend, but can also serve as a load balancer for requests going to the backend.
Backend
The backend is a scalable NodeJS / Redis / MongoDB app. Each backend server handles a group of SocketIO connections. User sessions are stored in a central Redis server. All data is stored in a central MongoDB server. The Redis and MongoDB servers are replicated to several secondary nodes, which can become the primary node if the current primary node goes down.
We currently only utilize 1 backend, 1 MongoDB server and 1 Redis server running for production, though it is relatively easy to expand.
Requirements
Installing with Docker: (not recommended for Windows users)
Standard Installation:
- NodeJS
nodemon:
yarn global add nodemonnode-gyp:yarn global add node-gyp - Yarn (Windows) Yarn (Unix) (npm can also be used)
- MongoDB Currently version 4.0
- Redis (Windows) Redis (Unix)
Getting Started
Once you've installed the required tools:
git clone https://github.com/Musare/MusareNode.gitcd MusareNodecp backend/config/template.json backend/config/default.jsonValues: The
modeshould be either "development" or "production". No more explanation needed.
Thesecretkey can be whatever. It's used by express's session module.
Thedomainshould be the url where the site will be accessible from, usuallyhttp://localhostfor non-Docker.
TheserverDomainshould be the url where the backend will be accessible from, usuallyhttp://localhost:8080for non-Docker.
TheserverPortshould be the port where the backend will listen on, should always be8080for Docker, and is recommended for non-Docker.isDockerif you are using Docker or not.
Theapis.youtube.keyvalue can be obtained by setting up a YouTube API Key. You need to use the YouTube Data API v3, and create an API key.
Theapis.recaptcha.secretvalue can be obtained by setting up a ReCaptcha Site (v3).
Theapis.githubvalues can be obtained by setting up a GitHub OAuth Application. You need to fill in some values to create the OAuth application. The homepage is the homepage of frontend. The authorization callback url is the backend url with/auth/github/authorize/callbackadded at the end. For examplehttp://localhost:8080/auth/github/authorize/callback.
Theapis.discord.tokenis the token for the Discord bot.
Theapis.discord.loggingServeris the Discord logging server id.
Theapis.discord.loggingChannelis the Discord logging channel id.
Theapis.mailgunvalues can be obtained by setting up a Mailgun account, or you can disable it.
Theapis.spotifyvalues can be obtained by setting up a Spotify client id, or you can disable it.
Theredis.urlurl should be left alone for Docker, and changed toredis://localhost:6379/0for non-Docker.
Theredis.passwordshould be the Redis password you either put in yourstartRedis.cmdfile for Windows, or.envfor docker.
Themongo.urlneeds to have the proper password for the MongoDB musare user, and for non-Docker you need to replace@musare:27017with@localhost:27017.
Thecookie.domainvalue should be the ip or address you use to access the site, without protocols (http/https), so for examplelocalhost.
Thecookie.securevalue should betruefor SSL connections, andfalsefor normal http connections.cp frontend/build/config/template.json frontend/build/config/default.jsonValues:
TheserverDomainshould be the url where the backend will be accessible from, usuallyhttp://localhost:8080for non-Docker. ThefrontendDomainshould be the url where the frontend will be accessible from, usuallyhttp://localhostfor docker orhttp://localhost:80for non-Docker. ThefrontendPortshould be the port where the frontend will be accessible from, should always be port81for Docker, and is recommended to be port80for non-Docker. Therecaptcha.keyvalue can be obtained by setting up a ReCaptcha Site (v3). Thecookie.domainvalue should be the ip or address you use to access the site, without protocols (http/https), so for examplelocalhost. Thecookie.securevalue should betruefor SSL connections, andfalsefor normal http connections. ThesiteSettings.logoshould be the path to the logo image, by default it is/assets/wordmark.png. ThesiteSettings.siteNameshould be the name of the site. ThesiteSettings.socialLinks.github,twitter,facebookandgithubare set to the official Musare accounts by default but can be changed.
Now you have different paths here.
Installing with Docker
Configuration
To configure docker simply cp .env.example .env and configure the .env file to match your settings in backend/config/default.json.
The configurable ports will be how you access the services on your machine, or what ports you will need to specify in your nginx files when using proxy_pass.
COMPOSE_PROJECT_NAME should be a unique name for this installation, especially if you have multiple instances of Musare on the same machine.
FRONTEND_MODE should be either dev or prod (self-explanatory).
Build the backend and frontend Docker images (from the main folder)
docker-compose buildSet up the MongoDB database
Set the password for the admin/root user.
In
.envset the environment variable ofMONGO_ROOT_PASSWORD.Set the password for the musare user (the one the backend will use).
In
.envset the environment variable ofMONGO_USER_USERNAMEandMONGO_USER_PASSWORD.Start the database (in detached mode), which will generate the correct MongoDB users.
docker-compose up -d mongo
3) Start redis and the mongo client in the background, as we usually don't need to monitor these for errors
docker-compose up -d mongoclient redis
4) Start the backend and frontend in the foreground, so we can watch for errors during development
docker-compose up backend frontend
5) You should now be able to begin development! The backend is auto reloaded when
you make changes and the frontend is auto compiled and live reloaded by webpack
when you make changes. You should be able to access Musare in your local browser
at http://<docker-machine-ip>:8080/ where <docker-machine-ip> can be found below:
Docker for Windows / Mac: This is just
localhostDocker ToolBox: The output of
docker-machine ip default
If you are using linting extensions in IDEs/want to run yarn lint, you need to install the following locally (outside of Docker):
yarn global add eslint
yarn add eslint-config-airbnb-baseStandard Installation
Steps 1-4 are things you only have to do once. The steps to start servers follow.
In the main folder, create a folder called
.databaseCreate a file called
startMongo.cmdin the main folder with the contents:"C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe" --dbpath "D:\Programming\HTML\MusareNode\.database"Make sure to adjust your paths accordingly.
Set up the MongoDB database
Start the database by executing the script
startMongo.cmdyou just madeConnect to Mongo from a command prompt
mongo adminCreate an admin user
db.createUser({user: 'admin', pwd: 'PASSWORD_HERE', roles: [{role: 'userAdminAnyDatabase', db: 'admin'}]})Connect to the Musare database
use musareCreate the musare user
db.createUser({user: 'musare', pwd: 'OTHER_PASSWORD_HERE', roles: [{role: 'readWrite', db: 'musare'}]})Exit
exitAdd the authentication
In
startMongo.cmdadd--authat the end of the first line
In the folder where you installed Redis, edit the
redis.windows.conffile. In there, look for the propertynotify-keyspace-events. Make sure that property is uncommented and has the valueEx. It should look likenotify-keyspace-events Exwhen done.Create a file called
startRedis.cmdin the main folder with the contents:"D:\Redis\redis-server.exe" "D:\Redis\redis.windows.conf" "--requirepass" "PASSWORD"And again, make sure that the paths lead to the proper config and executable. Replace
PASSWORDwith your Redis password.
Non-docker start servers
Automatic
- If you are on Windows you can run
windows-start.cmdor just double click thewindows-start.cmdfile and all servers will automatically start up.
Manual
Run
startRedis.cmdandstartMongo.cmdto start Redis and Mongo.In a command prompt with the pwd of frontend, run
yarn run devIn a command prompt with the pwd of backend, run
nodemon
Extra
Below is a list of helpful tips / solutions we've collected while developing MusareNode.
Mounting a non-standard directory in Docker Toolbox on Windows
Docker Toolbox usually only gives VirtualBox access to C:/Users of your
local machine. So if your code is located elsewere on your machine,
you'll need to tell Docker Toolbox how to find it. You can use variations
of the following commands to give Docker Toolbox access to those files.
First lets ensure the machine isn't running
docker-machine stop defaultNext we'll want to tell the machine about the folder we want to share.
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" sharedfolder add default --name "d/Projects/MusareNode" --hostpath "D:\Projects\MusareNode" --automountNow start the machine back up and ssh into it
docker-machine start default && docker-machine ssh defaultTell boot2docker to mount our volume at startup, by appending to its startup script
sudo tee -a /mnt/sda1/var/lib/boot2docker/profile >/dev/null <<EOF mkdir -p /d/Projects/MusareNode mount -t vboxsf -o uid=1000,gid=50 d/Projects/MusareNode /d/Projects/MusareNode EOFRestart the docker machine so that it uses the new shared folder
docker-machine restart defaultYou now should be good to go!
Fixing the "couldn't connect to docker daemon" error
Some people have had issues while trying to execute the docker-compose command.
To fix this, you will have to run docker-machine env default.
This command will print various variables.
At the bottom, it will say something similar to @FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i.
Run this command in your shell. You will have to do this command for every shell you want to run docker-compose in (every session).
Running Musare locally without using Docker
Install nodemon globally
yarn global add nodemonInstall webpack globally
yarn global add webpackInstall node-gyp globally (first check out https://github.com/nodejs/node-gyp#installation)
yarn global add node-gyp.Run
yarn run bootstrapto install dependencies and dev-dependencies for both the frontend and backend.Either execute
yarn run dev:frontendandyarn run dev:backendseparately, or in parallel withyarn dev.
Calling Toasts
You can call Toasts using our custom package, vue-roaster, using the following code:
import { Toast } from "vue-roaster";
Toast.methods.addToast("", 0);Set user role
When setting up you will need to grant yourself the admin role, using the following commands:
docker-compose exec mongo mongo admin
use musare
db.auth("MUSAREDBUSER","MUSAREDBPASSWORD")
db.users.update({username: "USERNAME"}, {$set: {role: "admin"}})