Skip to content

Commit

Permalink
服务器地址通过环境变量,在编译时获取
Browse files Browse the repository at this point in the history
  • Loading branch information
mylxsw committed Oct 9, 2023
1 parent e4ae9c4 commit d4199b2
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM nginx:1.25

COPY build/web/ /data/webroot
COPY nginx.conf /etc/nginx/conf.d/default.conf
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ build-web:
rm -fr build/web/fonts/ && mkdir build/web/fonts
cp -r scripts/s build/web/fonts/s

build-web-samehost:
flutter build web --web-renderer canvaskit --release --dart-define=API_SERVER_URL=/
cd scripts && go run main.go ../build/web/main.dart.js && cd ..
rm -fr build/web/fonts/ && mkdir build/web/fonts
cp -r scripts/s build/web/fonts/s

deploy-web: build-web
cd build && tar -zcvf web.tar.gz web
scp build/web.tar.gz huawei-1:/data/webroot
ssh huawei-1 "cd /data/webroot && tar -zxvf web.tar.gz && rm -rf web.tar.gz app && mv web app"
rm -fr build/web.tar.gz

.PHONY: run build-android build-macos ipa
.PHONY: run build-android build-macos ipa build-web-samehost build-web deploy-web
20 changes: 20 additions & 0 deletions docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

VERSION=1.0.6
VERSION_DATE=202310091100

rm -fr build/web

flutter build web --web-renderer canvaskit --release --dart-define=API_SERVER_URL=/
cd scripts && go run main.go ../build/web/main.dart.js && cd ..
rm -fr build/web/fonts/ && mkdir build/web/fonts
cp -r scripts/s build/web/fonts/s

docker build -t mylxsw/aidea-web:$VERSION .
docker tag mylxsw/aidea-web:$VERSION mylxsw/aidea-web:$VERSION_DATE
docker tag mylxsw/aidea-web:$VERSION mylxsw/aidea-web:latest

docker push mylxsw/aidea-web:$VERSION
docker push mylxsw/aidea-web:$VERSION_DATE
docker push mylxsw/aidea-web:latest

4 changes: 0 additions & 4 deletions lib/helper/constant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ const databaseVersion = 25;
const maxRoomNumForNonVIP = 50;
const coinSign = '个';

// API 服务器地址
const apiServerURL = 'https://ai-api.aicode.cc';
// const apiServerURL = 'http://localhost';

const settingAPIServerToken = 'api-token';
const settingUserInfo = 'user-info';
const settingUsingGuestMode = 'using-guest-mode';
Expand Down
14 changes: 14 additions & 0 deletions lib/helper/env.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// API 服务器地址
String get apiServerURL {
var url = const String.fromEnvironment(
'API_SERVER_URL',
defaultValue: 'https://ai-api.aicode.cc',
);

// 当配置的 URL 为 / 时,自动替换为空,用于 Web 端
if (url == '/') {
return '';
}

return url;
}
2 changes: 1 addition & 1 deletion lib/helper/http.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:askaide/helper/constant.dart';
import 'package:askaide/helper/env.dart';
import 'package:askaide/helper/logger.dart';
import 'package:askaide/helper/platform.dart';
import 'package:dio/dio.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/page/setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:askaide/bloc/account_bloc.dart';
import 'package:askaide/helper/ability.dart';
import 'package:askaide/helper/cache.dart';
import 'package:askaide/helper/env.dart';
import 'package:askaide/helper/helper.dart';
import 'package:askaide/helper/http.dart';
import 'package:askaide/helper/logger.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/page/signin_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:askaide/bloc/version_bloc.dart';
import 'package:askaide/helper/ability.dart';
import 'package:askaide/helper/constant.dart';
import 'package:askaide/helper/env.dart';
import 'package:askaide/helper/helper.dart';
import 'package:askaide/helper/logger.dart';
import 'package:askaide/helper/platform.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/page/signup_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';

import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:askaide/helper/constant.dart';
import 'package:askaide/helper/env.dart';
import 'package:askaide/helper/helper.dart';
import 'package:askaide/lang/lang.dart';
import 'package:askaide/page/component/background_container.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/repo/api_server.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:askaide/helper/constant.dart';
import 'package:askaide/helper/env.dart';
import 'package:askaide/helper/error.dart';
import 'package:askaide/helper/http.dart';
import 'package:askaide/helper/logger.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/repo/deepai_repo.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:askaide/helper/constant.dart';
import 'package:askaide/helper/env.dart';
import 'package:askaide/helper/platform.dart';
import 'package:askaide/repo/data/settings_data.dart';
import 'package:http/http.dart' as http;
Expand Down
1 change: 1 addition & 0 deletions lib/repo/openai_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';
import 'package:askaide/helper/ability.dart';
import 'package:askaide/helper/constant.dart';
import 'package:askaide/helper/env.dart';
import 'package:askaide/helper/platform.dart';
import 'package:askaide/repo/model/model.dart' as mm;
import 'package:dart_openai/openai.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/repo/stabilityai_repo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:askaide/helper/constant.dart';
import 'package:askaide/helper/env.dart';
import 'package:askaide/helper/platform.dart';
import 'package:askaide/repo/data/settings_data.dart';
import 'package:http/http.dart' as http;
Expand Down
15 changes: 15 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen 80;

gzip on;
gzip_static on;
gzip_vary on;
gzip_types text/plain application/x-javascript text/css application/xml text/xml application/javascript;

root /data/webroot;

location / {
index index.html;
try_files $uri $uri/ =404;
}
}

0 comments on commit d4199b2

Please sign in to comment.