×
Community Blog Creating a Web Game Map App Using Leaflet, PostgreSQL/PostGIS, and Redis on Alibaba Cloud

Creating a Web Game Map App Using Leaflet, PostgreSQL/PostGIS, and Redis on Alibaba Cloud

This article shows a demo of an interactive Game of Thrones map powered by Leaflet, PostgreSQL/PostGIS, and Redis on Alibaba Cloud.

You can access the tutorial artifact, including the deployment script (Terraform), related source code, sample data, and instruction guidance from this GitHub project.

For more tutorials about Alibaba Cloud Database, please refer to this link.

Database Deployment Tutorials Series: https://community.alibabacloud.com/series/118

Overview

This is a demo of building an interactive Game of Thrones (https://github.com/andi1991/Atlas-Of-Thrones) map powered by Leaflet, PostgreSQL/PostGIS, and Redis on Alibaba Cloud.

Deployment architecture:

1

Index

Step 1. Use Terraform to Provision ECS, PostgreSQL Database, and Redis on Alibaba Cloud

Run the Terraform script. Please specify the necessary information and region to deploy it.

2

After the Terraform script execution is finished, the ECS instance information is listed as below:

3

  • eip_ecs: The public EIP of the ECS for game map application host
  • rds_pg_url: The connection endpoint URL of the RDS PostgreSQL database
  • rds_pg_port: The connection endpoint port of the RDS PostgreSQL database
  • redis_url: The connection endpoint URL of the Redis

2. Set up Sample Data in the RDS PostgreSQL Database

Click Elastic Compute Service, as shown in the following figure:

4

We can see one running ECS instance in the China (Hong Kong) region.

5

Copy this ECS instance's Internet IP address and log on to this ECS (Ubuntu system) instance remotely. For more details about remote login, please refer to login.

The default account name and password of the ECS instance:

Account name: root

Password: Aliyun-test

After logging in successfully, enter the following command to download the pre-prepared data script:

wget https://cdn.patricktriest.com/atlas-of-thrones/atlas_of_thrones.sql

6

Enter the following command to install the PostgreSQL client:

apt update && apt -y install postgresql-client

7

Enter the following command to connect to the PostgreSQL instance. Please pay attention and replace YOUR-POSTGRESQL-ADDRESS with the connection address of the user's PostgreSQL instance:

psql -h YOUR-POSTGRESQL-ADDRESS -p 5432 -U patrick -d atlas_of_thrones 

8

Password: the_best_passsword

Enter the following command to install the PostGIS extension. If the prompt already exists, it doesn’t matter; proceed to the following operations directly:

CREATE EXTENSION postgis;

9

Enter the following command to exit the client:

\q

10

Enter the following command, and load the downloaded SQL dump into your newly created database. Please pay attention and replace YOUR-POSTGRESQL-ADDRESS with the connection address of your PostgreSQL instance:

psql -h YOUR-POSTGRESQL-ADDRESS  -p 5432 -U patrick -d atlas_of_thrones < atlas_of_thrones.sql

11

Password: the_best_passsword

Enter the following command to log in to the "atlas_of_thrones" database. Please pay attention and replace YOUR-POSTGRESQL-ADDRESS with the connection address of the user's PostgreSQL instance:

psql -h YOUR-POSTGRESQL-ADDRESS  -p 5432 -U patrick -d atlas_of_thrones

12

Password: the_best_passsword

Enter the following command to get a list of available tables:

\dt

13

Enter the following command to inspect the schema of an individual table by running:

\d kingdoms

14

Enter the following command to query data:

SELECT name, claimedby, gid FROM kingdoms;

15

Enter the following command to exit the client:

\q

16

3. Install NodeJS

Enter the following command to download the Nodejs installation package:

wget http://labex-ali-data.oss-us-west-1.aliyuncs.com/nodejs/node-v12.13.0-linux-x64.tar.xz

17

Enter the following command to decompress the installation package:

tar -xf node-v12.13.0-linux-x64.tar.xz

18

Enter the following command to move the unzipped directory to the "/usr/local" directory:

mv node-v12.13.0-linux-x64 /usr/local/node

19

Enter the command: vim /etc/profile and add the following content to the file:

export NODE_HOME=/usr/local/node
export PATH=$PATH:$NODE_HOME/bin

20

Enter the following command to make the modification effective:

source /etc/profile

21

Enter the following command to view the installed version, indicating that the installation is complete:

node -v

npm -v

22

4. Deploy and Run the Demo Game Map Project

Enter the following command to install the Git tool:

apt -y install git

23

Enter the following command to download the project:

git clone -b labex https://github.com/andi1991/Atlas-Of-Thrones.git

24

Enter the following command to enter the project directory:

cd Atlas-Of-Thrones

25

Enter the command: vim .env, copy the following content to the file. Please pay attention and replace YOUR-POSTGRESQL-ADDRESS 、YOUR-REDIS-ADDRESS with the connection address of your instance:

PORT=5000
DATABASE_URL=postgres://patrick:the_best_passsword@YOUR-POSTGRESQL-ADDRESS:5432/atlas_of_thrones?ssl=false
REDIS_HOST=YOUR-REDIS-ADDRESS
REDIS_PORT=6379
CORS_ORIGIN=http://localhost:8080

26

Enter the following command to install related dependencies:

npm install

27

Enter the following command to install the dependent package that reported the error separately.

npm cache clean --force

npm i --unsafe-perm node-sass@4.14.1

28

Enter the following command to start the service:

npm run dev

29

Access the service in the browser and enter the link below. Please pay attention and replace YOUR-ECS-PUBLIC-IP with the user's ECS public IP address:

YOUR-ECS-PUBLIC-IP:8080

30

Game map service deployment is completed.

Authors of this Tutorial

0 1 0
Share on

ApsaraDB

459 posts | 98 followers

You may also like

Comments

ApsaraDB

459 posts | 98 followers

Related Products