Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

允许特定源的请求跨域CORS #21

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# 使用python:3.8-slim-buster作为基础镜像
FROM python:3.8-slim-buster

# 创建app目录来存储我们的代码
RUN mkdir /app

COPY ./*.txt ./*.py ./*.sh ./*.onnx /app/
# 将工作目录设置为/app,这意味着后续的指令都在/app下执行
WORKDIR /app

# 将当前目录(即你的项目目录)下的所有文件和文件夹复制到镜像的/app目录下
COPY . /app

RUN cd /app \
&& python3 -m pip install --upgrade pip -i https://pypi.douban.com/simple/\
&& pip3 install --no-cache-dir -r requirements.txt --extra-index-url https://pypi.douban.com/simple/ \
&& rm -rf /tmp/* && rm -rf /root/.cache/* \
&& sed -i 's#http://deb.debian.org#http://mirrors.aliyun.com/#g' /etc/apt/sources.list\
&& apt-get --allow-releaseinfo-change update && apt install libgl1-mesa-glx libglib2.0-0 -y
# 安装Python依赖
RUN pip3 install --no-cache-dir requirements.txt

WORKDIR /app

# 定义容器启动时要运行的命令
CMD ["python3", "ocr_server.py", "--port", "9898", "--ocr", "--det"]
4 changes: 4 additions & 0 deletions ocr_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

import ddddocr
from flask import Flask, request
from flask_cors import CORS

app = Flask(__name__)
CORS(app, origins=["http://example.com"])

parser = argparse.ArgumentParser(description="使用ddddocr搭建的最简api服务")
parser.add_argument("-p", "--port", type=int, default=9898)
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ddddocr>=1.3.1
flask
ddddocr
flask
flask-cors