Code Monkey home page Code Monkey logo

serveit's Introduction

serveit

The spendit backend

Install

In this project, run npm install

Important directories

  • src - source code
  • dist - compiled code
  • data - data files (storage of certificates, config files etc.)
    • config - configuration files
    • certs - ssl certificates

Setup

MongoDB

Provided in this project is a docker-compose file that will setup a mongodb instance with a persistent volume. To use it, run docker compose -f docker-compose.database.yml up -d in the project directory. This will start a mongodb instance on port 27017 with a persistent volume in the mongodata directory. If you are using the provided docker-compose file, you do not need to set the DB_URL environment variable to 127.0.0.1.

You can also use your own mongodb instance, but you will need to set the DB_URL, DB_PORT, DB_USER, and DB_PASS environment variables to the correct values.

Environment Variables

Before the server can be used in production, the following enivronment variables must be set:

  • NODE_ENV (production/development)
  • DB_URL (mongodb url)
  • DB_PORT (mongodb port, only needed for localhost url)
  • DB_USER (mongodb username)
  • DB_PASS,
  • INCLUDE_APP (true/false) [whether the backend server should serve the frontend app]
  • INCLUDE_GOOGLE (true/false) [whether the backend server should use google services (gmail, google oauth, etc.)]
  • BACKEND_PORT (port to run backend server on)
  • BACKEND_DOMAIN (domain to run backend server on)
  • SELFSIGN (true/false) [whether you need a ssl certificate for the backend server or if you are providing one yourself]
  • CF_TOKEN (cloudflare api token) [if set and domain dns is managed by cloudflare, the ssl certificate will be a proper certificate using a certificate authority and not an insecure self-signed one]

For example, a typical enviroment variables for production would look like:

NODE_ENV=production
DB_URL=127.0.0.1 #For DB hosted on same machine as server with default port and no username/password
INCLUDE_APP=true #Only needed if serving frontend app from backend server
INCLUDE_GOOGLE=true #Only needed if using/testing google services
BACKEND_PORT=3030 #Port to run backend server on
BACKEND_DOMAIN=phrydge.engphys.com #Domain to run backend server on
SELFSIGN=true #Make backend manage ssl certificate
CF_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #Cloudflare api token for valid ssl certificate generation

First Run

On the first run, the the server will produce a setup link in the console and logs that you must visit to setup the server. It will go through the following steps:

  1. Create a new admin account
  2. Configure email settings
    • Allows you to choose between using gmail, smtp, or mock email, or no email at all
    • If using gmail, you must have set the INCLUDE_GOOGLE environment variable to true and have a google_credentials.json file in the config folder. (the setup page will tell you how to get this file).
    • If using smtp, additional configuration options will be available to set the host, port, username, and password, and whether to use secure connection (tls/ssl).
  3. If INCLUDE_GOOGLE is set to true, you will be asked to authorize the server for all the configured scopes. This is required for the server to use google services.
  4. The last step is to configure the storefronts branding (currently not implemented)

The email and branding settings can be changed at any time in the config folder.

Starting the server

Production

First build project: npm run build then setup either a nodemon, systemctl service, or cpanel node.js application

Nodemon

WIP

Systemctl Service

The following is an example of a systemd service file for the backend server.

[Unit]
Description=Phrydge Dev Node Website
After=network-online.target

[Service]
# Set working directory
WorkingDirectory=/srv/phrydge-dev/
ExecStart=/usr/bin/node /srv/phrydge-dev/backend/index.js 
Restart=always
# Set environment variables from .env file
EnvironmentFile = /srv/phrydge-dev/.env

[Install]
WantedBy=multi-user.target

Create the service file in /etc/systemd/system/service-name.service and enable it with systemctl enable service-name.service. Then start the service with systemctl start service-name.service.

Cpanel Node.js Application

WIP

Development

For live compiling and reload while developing run: npm run watch

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.