Skip to content

Commit 4f05766

Browse files
committed
rename build.py and enable CORS
1 parent ea48b8b commit 4f05766

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

build/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ WORKDIR /app/
55
COPY build/requirements.txt .
66
RUN pip install -r requirements.txt
77

8-
COPY build/build.py build.py
8+
COPY build/main.py main.py
99

1010
ENV BASEURL="https://cp-algorithms.com"
1111
VOLUME /input
1212
VOLUME /output
1313

14-
CMD python build.py -i /input/src -o /output --template-dir /input/src/_templates --static-dir /input/static --baseurl $BASEURL
14+
CMD python main.py -i /input/src -o /output --template-dir /input/src/_templates --static-dir /input/static --baseurl $BASEURL

build/build.py renamed to build/main.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from urllib.parse import urljoin
1313
import shutil
1414
from tempfile import TemporaryDirectory
15+
from typing import Dict, Tuple
1516

1617
import markdown # type: ignore
1718
from tqdm import tqdm # type: ignore
@@ -137,7 +138,17 @@ def convert(self, md_content: str, relative_url: Path) -> str:
137138
return content
138139

139140

140-
def convert(request) -> str:
141+
def convert(request) -> Tuple[str, int, Dict]:
142+
# Set CORS headers for the preflight request
143+
if request.method == 'OPTIONS':
144+
headers = {
145+
'Access-Control-Allow-Origin': '*',
146+
'Access-Control-Allow-Methods': 'POST',
147+
'Access-Control-Allow-Headers': 'Content-Type',
148+
'Access-Control-Max-Age': '3600'
149+
}
150+
return ('', 204, headers)
151+
141152
request_json = request.get_json()
142153

143154
# prepare markdown converter
@@ -160,7 +171,10 @@ def convert(request) -> str:
160171
md_content = request_json['markdown']
161172
html_content = md.convert(md_content, Path("."))
162173

163-
return html_content
174+
headers = {
175+
'Access-Control-Allow-Origin': '*'
176+
}
177+
return (html_content, 200, headers)
164178

165179

166180
def main():

0 commit comments

Comments
 (0)