Project using Go + Nuxt.js
Make sure Go is already installed on your PC.
Clone this repository and install all required dependencies.
Create config.env
file and setup the following variables:
db_user = *your_username*
db_pass = *your_password*
db_name = *your_database_name*
db_host = localhost
db_port = *postgres_server_port*
Type the following code in the terminal to run the API server:
$ go run server.go
Then type the following to run the development server:
$ cd client
$ npm run dev
Notes-App works with postgresql, nuxt, golang.
Our service checked in deb distros + apache2.
First, let's clone Notes-App
git clone https://github.com/on3dd/Notes-App.git
Let's install the Database
sudo apt update
sudo apt install postgresql postgresql-contrib
Login to postgresql
sudo -u postgres psql
Create Database & User
CREATE DATABASE yourdbname;
CREATE USER youruser WITH ENCRYPTED PASSWORD 'yourpass';
GRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser;
\q
Import tables
CREATE TABLE "messages" (
"id" serial NOT NULL,
"text" TEXT NOT NULL,
"category_id" int NOT NULL,
"posted_at" TIMESTAMP NOT NULL,
"author_id" int NOT NULL,
CONSTRAINT "messages_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
CREATE TABLE "categories" (
"id" int NOT NULL,
"name" varchar(255) NOT NULL,
"parent_id" int,
CONSTRAINT "categories_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
CREATE TABLE "users" (
"id" int NOT NULL,
"name" varchar(255) NOT NULL,
CONSTRAINT "users_pk" PRIMARY KEY ("id")
) WITH (
OIDS=FALSE
);
Create config.env in Notes-App/
cd Notes-App/
echo "db_user = *your_username*" >> config.env
echo "db_pass = *your_password*" >> config.env
echo "db_name = *your_database_name*" >> config.env
echo "db_host = localhost" >> config.env
echo "db_port = *postgres_server_port*" >> config.env
Please install latest version from PPA
curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs
rm nodesource_setup.sh
Check versions
nodejs -v
npm -v
App checked in node js v8.16.2 & npm v6.4.1
Install nodejs dependencies
npm install Notes-App/client
This will give you latest version of go
sudo snap install --classic go
You have to move Notes-App/ to $GOROOT
cd .. && mv Notes-App/ $GOROOT/src/Notes-App/
Check version
go version
App checked in go v1.13.4
cd Notes-App/api
go install
cd .. && go install
Install Apache2
sudo apt install apache2
Touch virtual host
sudo vi /etc/apache2/sites-aviable/your_host.conf
And describe host
<VirtualHost *:80>
ServerAdmin ServerAdmin@host.ru
ServerName your_hostname
ServerAlias www.your_hostname
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
</VirtualHost>
Lauch your virtual host
sudo a2ensite your_host.conf
sudo service apache2 restart
Let your Firewall access Apache2
sudo ufw allow 'Apache'
Sure, we can run our App how service. Just create new service
sudo vi /etc/systemd/system/Notes-App-server.service
And describe service
[Unit]
Description=Notes-App-server
After=network-online.target
[Service]
Restart=on-failure
WorkingDirectory=$GOROOT/src/Notes-App/
ExecStart=/snap/bin/go run server.go
User=USER
[Install]
WantedBy=multi-user.target
Where User - who a you. Let repeat this for server.
Touch Notes-App-client.service
sudo vi /etc/systemd/system/Notes-App-client.service
And describe service
[Unit]
Description=Notes-App-client
After=network-online.target
[Service]
Restart=on-failure
WorkingDirectory=$GOROOT/src/Notes-App/client/
ExecStart=/usr/bin/node run dev
User=USER
[Install]
WantedBy=multi-user.target
Reload systemd daemon and enable ours services
systemctl daemon-reload
systemctl enable Notes-App-client.service
systemctl enale Notes-App-server.service
Well, we can see our job in youhostname