Commit 528b1483 authored by xiezhi's avatar xiezhi

fix

parent a0612ce7
# 使用仓颉1.0.1作为基础镜像
FROM hb.eazytec-cloud.com/eazytec/eazydevelop-cangjie:ubuntu20.04-cangjie1.0.1-latest
FROM hb.eazytec-cloud.com/eazytec/eazydevelop-cangjie:ubuntu22.04-cangjie1.0.1-latest
# 设置工作目录
WORKDIR /app
......@@ -18,7 +18,7 @@ RUN chmod +x docker-entrypoint.sh
RUN make install
# 设置环境变量
ENV APP_PORT_1=8080
ENV APP_PORT_1=8000
# 暴露端口
EXPOSE $APP_PORT_1
......
......@@ -3,7 +3,7 @@ APP_NAME = cangjie1.0.1-hello-world
CANGJIE_VERSION = 1.0.1
MAIN_MODULE = HelloWorld
BUILD_DIR = target
APP_PORT = $(or $(APP_PORT_1),8080)
APP_PORT = $(or $(APP_PORT_1),8000)
LOG_FILE = $(abspath $(dir $(lastword $(MAKEFILE_LIST))))/.logs/app.log
PID_FILE = $(abspath $(dir $(lastword $(MAKEFILE_LIST))))/.logs/app.pid
......@@ -131,4 +131,4 @@ help:
@echo " make restart # 重启服务器"
@echo ""
@echo "环境变量:"
@echo " APP_PORT_1 - 服务器端口(默认: 8080)"
@echo " APP_PORT_1 - 服务器端口(默认: 8000)"
......@@ -42,7 +42,7 @@ cangjie1_0_1_template/
cjpm build
# 运行 HTTP 服务器
APP_PORT_1=8080 cjpm run
APP_PORT_1=8000 cjpm run
```
### 方法二:使用 Makefile
......@@ -80,10 +80,10 @@ make help
docker build -t cangjie1.0.1-hello-world .
# 运行容器
docker run -p 8080:8080 cangjie1.0.1-hello-world
docker run -p 8000:8000 cangjie1.0.1-hello-world
# 运行容器并指定端口
docker run -p 9090:8080 -e APP_PORT_1=8080 cangjie1.0.1-hello-world
docker run -p 9090:8000 -e APP_PORT_1=8000 cangjie1.0.1-hello-world
```
## 服务器使用示例
......@@ -93,12 +93,12 @@ docker run -p 9090:8080 -e APP_PORT_1=8080 cangjie1.0.1-hello-world
make run
# 输出:
# ✅ 仓颉 HTTP 服务器已启动,PID: 12345
# 服务器运行在: http://localhost:8080/
# 服务器运行在: http://localhost:8000/
```
### 访问服务器
```bash
curl http://localhost:8080/
curl http://localhost:8000/
# 输出:Hello Cangjie!
```
......@@ -107,7 +107,7 @@ curl http://localhost:8080/
make status
# 输出:
# ✅ 服务器正在运行,PID: 12345
# 端口: 8080
# 端口: 8000
# 日志: /path/to/.logs/app.log
```
......@@ -126,7 +126,7 @@ make stop
HTTP 服务器类包含以下功能:
- **main 函数**: 程序入口点,启动 HTTP 服务器
- **端口配置**: 硬编码端口 8080,可通过环境变量 APP_PORT_1 覆盖
- **端口配置**: 硬编码端口 8000,可通过环境变量 APP_PORT_1 覆盖
- **HTTP 处理器**: 使用 Lambda 表达式处理 HTTP 请求
- **服务器启动**: 使用仓颉原生 HTTP 库创建 HTTP 服务
......@@ -156,11 +156,11 @@ HTTP 服务器类包含以下功能:
- 基于仓颉 1.0.1 镜像
- 使用 cjpm 编译和运行 HTTP 服务器
- 支持端口配置(APP_PORT_1 环境变量)
- 暴露 8080 端口
- 暴露 8000 端口
## 环境变量
- `APP_PORT_1`: HTTP 服务器端口号(默认: 8080,代码中硬编码为 8080)
- `APP_PORT_1`: HTTP 服务器端口号(默认: 8000,代码中硬编码为 8000)
## 仓颉语言特性
......@@ -188,7 +188,7 @@ HTTP 服务器类包含以下功能:
## 注意事项
- 当前代码中端口硬编码为 8080,环境变量 APP_PORT_1 暂时未生效
- 当前代码中端口硬编码为 8000,环境变量 APP_PORT_1 暂时未生效
- 项目使用 cjpm 作为包管理器,需要确保已安装 cjpm
- 编译后的文件位于 `target` 目录
......
[package]
cjc-version = "1.0.1"
name = "cangjie1_0_1_template"
name = "workspace"
description = "仓颉1.0.1 HTTP服务器示例"
version = "1.0.0"
target-dir = ""
......@@ -13,7 +13,13 @@
[dependencies]
[target.aarch64-apple-darwin]
link-option = "-L/opt/homebrew/lib -lssl -lcrypto"
[target.aarch64-apple-darwin.bin-dependencies]
path-option = [ "${CANGJIE_STDX_PATH}/darwin_aarch64_llvm/dynamic/stdx"]
[target.x86_64-unknown-linux-gnu]
[target.x86_64-unknown-linux-gnu.bin-dependencies]
path-option = ["${CANGJIE_STDX_PATH}/linux_x86_64_llvm/static/stdx"]
\ No newline at end of file
......@@ -7,7 +7,7 @@ set -e
echo "=== 仓颉 1.0.1 HTTP 服务器容器启动 ==="
echo "仓颉版本: $(cjc -v 2>&1 | head -n 1)"
echo "工作目录: $(pwd)"
echo "端口: ${APP_PORT_1:-8080}"
echo "端口: ${APP_PORT_1:-8000}"
echo ""
# 检查仓颉编译器是否可用
......@@ -30,6 +30,6 @@ fi
# 运行HTTP服务器
echo "启动仓颉 HTTP 服务器..."
echo "服务器将在端口 ${APP_PORT_1:-8080} 上运行"
echo "服务器将在端口 ${APP_PORT_1:-8000} 上运行"
echo "=========================================="
exec cjpm run
package cangjie1_0_1_template
package workspace
import stdx.net.http.*
import std.time.*
......@@ -11,8 +11,8 @@ import std.core.*
* 使用仓颉原生HTTP库实现HTTP服务
*/
main() {
// 从环境变量获取端口,默认为8080
let port :UInt16 = 8080
// 从环境变量获取端口,默认为8000
let port :UInt16 = 8000
// 构建 Server 实例
......@@ -29,7 +29,7 @@ main() {
// 设置日志级别
server.logger.level = LogLevel.OFF
println("仓颉 HTTP 服务器运行在 http://0.0.0.0:8080" + "/")
println("仓颉 HTTP 服务器运行在 http://0.0.0.0:8000" + "/")
// 启动服务
server.serve()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment