add deploy static

This commit is contained in:
Shaun Chyxion 2020-09-05 13:10:50 +08:00
parent 45f32e0523
commit 7bd2b582fe
3 changed files with 194 additions and 4 deletions

58
deploy-static.sh Executable file
View File

@ -0,0 +1,58 @@
#!/bin/bash
# get real path of softlink
get_real_path() {
local f="$1"
while [ -h "$f" ]; do
ls=`ls -ld "$f"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
f="$link"
else
f=`dirname "$f"`/"$link"
fi
done
echo "$f"
}
prg_path=$(get_real_path "$0")
echo "Script path [$prg_path]"
# Service Home
pushd $(dirname "$prg_path") > /dev/null
WORK_DIR=$(pwd)
echo "Work dir [$WORK_DIR]"
if [ "$1" == "test" ]; then
echo "Deploy test."
server='xiadou@118.24.251.131'
port=22
elif [ "$1" == "prod" ]; then
echo "Deploy prod."
server='xiandou@localhost'
port=4025
else
echo 'Usage: ./deploy-static.sh test|prod'
exit 1
fi
APP='cms'
buildDir="$APP-static"
buildTgz="$buildDir.tar.gz"
targetPath='/data/program'
prevDir="$targetPath/$buildDir.prev"
# ember build
cd "web/$APP"
rm -rf $buildDir $buildTgz
ember b -prod -o "$APP-static"
tar czvf $buildTgz $buildDir
# mv prev
ssh -p $port $server "rm -rf $prevDir && mv $targetPath/$buildDir $prevDir"
# extract
ssh -p $port $server "tar xzv -C /data/program" < $buildTgz
rm -rf $buildDir $buildTgz
popd > /dev/null

132
nginx.conf Normal file
View File

@ -0,0 +1,132 @@
user root;
worker_processes 4;
#error_log logs/error.log;
error_log logs/error.log;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
# rewrite_log on;
include mime.types;
default_type application/octet-stream;
client_max_body_size 128M;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
upstream cas {
server 127.0.0.1:8081;
}
upstream cms {
server 127.0.0.1:8082;
}
upstream cms2 {
server 127.0.0.1:8087;
}
upstream openapi {
server 127.0.0.1:8084;
}
server {
listen 8080;
server_name localhost;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /download/phone {
add_header Content-Disposition 'attachment; filename="MicroSIP-Lite-3.20.0.zip"';
alias /data/program/download/MicroSIP-Lite-3.20.0.zip;
}
location /cas {
proxy_pass http://cas;
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# CMS Static
rewrite ^/(cms|cms2)$ /$1/ permanent;
location /cms {
alias /data/program/cms-static;
index index.html;
}
location /cms2 {
alias /data/program/cms-static;
index index.html;
}
# CMS API
rewrite ^/(cms|cms2)/api$ /$1/api/ permanent;
rewrite ^/(cms|cms2)/cas/(.+)$ /$1/api/cas/$2 break;
rewrite ^/(cms|cms2)/logout$ /$1/api/logout break;
location ~ ^/(cms|cms2)/api/ {
rewrite ^/(cms|cms2)/api/(.*) /$2 break;
proxy_pass http://$1;
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
rewrite ^/openapi$ /openapi/ permanent;
location /openapi {
rewrite ^/openapi/(.*)$ /$1 break;
proxy_pass http://openapi;
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /rec {
root /var/lib/freeswitch/recordings;
rewrite "^/rec/(([^_]+)_(\d{4})\-(\d{2})-(\d{2})_(\d{2})\-(\d{2})\-(\d{2})(_\w+)?([^.]+)?\.(\w+))$" "/$3/$4/$5/$6/$1" break;
}
location /sound {
root /data/program;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

View File

@ -11,11 +11,11 @@ const App = Application.extend({
});
$.ajaxSetup({
beforeSend(jqXHR) {
beforeSend(jqXHR, opt) {
jqXHR.setRequestHeader('X-Request-Type', 'Ajax');
// if (config.environment === 'production') {
// opt.url = '/api/' + opt.url;
// }
if (config.environment === 'production') {
opt.url = 'api/' + opt.url;
}
}
});