README.md 4.3 KB
Newer Older
nengyuangzhang's avatar
nengyuangzhang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# myems-web

## Introduction

Web用户界面,用于MyEMS能源数据可视化

Web UI for MyEMS energy data visualization

## Dependencies

nginx-1.18.0 or later

Node.js 17.0.0 or later

## Running in Local Environment for Development

* Install Node.js via binary archive on Linux

Download Current Linux Binaries (x64) from https://nodejs.org/en/download/current/

```bash
sudo mkdir -p /usr/local/lib/nodejs
23
sudo tar -xJvf node-vxx.x.x-linux-x64.tar.xz -C /usr/local/lib/nodejs
nengyuangzhang's avatar
nengyuangzhang 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
sudo ln -s /usr/local/lib/nodejs/node-vxx.x.x-linux-x64/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/nodejs/node-vxx.x.x-linux-x64/bin/npm /usr/bin/npm
sudo ln -s /usr/local/lib/nodejs/node-vxx.x.x-linux-x64/bin/npx /usr/bin/npx
```
Download the latest current version Windows installer (.msi) 64-bit from https://nodejs.org/en/download/current/
Install Node.js with Setup Wizard

Test installation
```bash
node -v
npm version
npx -v
```

* Download all the necessary dependencies into the node_modules directory.
```bash
cd myems/myems-web
npm i --unsafe-perm=true --allow-root --legacy-peer-deps
```

* If you modified any scss files then you need to compile SCSS, else you can safely ignore this step.
Run below command in your project directory to compile scss.
```bash
npm run scss
```

* Starting the Development Server
A local web server will start at http://localhost:3000.
We are using webpack and webpack-serve to automatically detect file changes. So, if you edit and save a file, your browser will automatically refresh and preview the change.
```bash
npm start
```

## Installation

### Option 1: Install myems-web on Docker

Refer to [myems.io](https://myems.io/docs/installation/docker-linux#step-8-myems-web)

### Option 2: Install myems-web on Server with NGINX

Refer to [myems.io](https://myems.io/docs/installation/debian-ubuntu#step-8-myems-web)

### Option 3: Install on Apache2 Server
* Install Apache2 Server

refer to https://httpd.apache.org/docs/2.4/install.html

* Configure Apache2
```bash
sudo vi /etc/apache2/ports.conf
```
Add a Listen
```
Listen 80
```
```bash
sudo vi /etc/apache2/sites-available/000-default.conf
```
Add a new 'VirtualHost' as below
```
<VirtualHost 127.0.0.1:80>
        ServerAdmin MyEMS-web
        DocumentRoot /var/www/myems-web
88

nengyuangzhang's avatar
nengyuangzhang 已提交
89 90 91 92 93 94 95 96 97 98
        <Directory "var/www/myems-web">
                Options FollowSymLinks
                AllowOverride All
                Require all granted
    			Header set Access-Control-Allow-Origin *
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ProxyRequests Off
		ProxyPreserveHost On
99

nengyuangzhang's avatar
nengyuangzhang 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
		<Proxy *>
			Order Deny,Allow
			Allow from all
		</Proxy>
		ProxyPass /api http://127.0.0.1:8000/
		ProxyPassReverse /api http://127.0.0.1:8000/
</VirtualHost>
```

* Install MyEMS Web UI:

Check and change the config file if necessary:
```bash
cd myems/myems-web
sudo nano src/config.js
```

Build and Compress
```bash
cd myems/myems-web/
sudo npm run build
tar czvf myems-web.tar.gz build
```

124 125
Install
Upload the file myems-web.tar.gz to you web server.
nengyuangzhang's avatar
nengyuangzhang 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
Note that the following path should be same as that was configured in 000-default.conf
```bash
tar xzf myems-web.tar.gz
sudo rm -r /var/www/myems-web
sudo mv build  /var/www/myems-web
```
*   avoid 404 error while refreshing pages
```bash
cd /var/www/myems-web
sudo vi .htaccess
```
  Add a IfModule as below:
```bash
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>
```
  Configure rewrite.load
```bash
cd /etc/apache2/mods-enabled/
sudo vi rewrite.load
```
  Add content as below
```bash
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
```

### Option 4: Install myems-web on Node.js Web Server
* Run below command in your project directory to make the Production build.

This will create an optimized production build by compiling, merging and minifying all the source files as necessary and put them in the build/ folder.
```bash
sudo npm run build
```

* Run the production build locally at http://localhost:80.
    If you want to listen on other port, change it in myems/myems-web/server.js
```bash
sudo node server.js
```


### References

[1]. http://myems.io