From 8a7d062eb4217b1faf3fc539deb2f6263363717c Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Thu, 11 Aug 2022 12:59:35 +0300 Subject: [PATCH] devnginx --- migration/__init__.py | 1 - migrate.py => migration/__main__.py | 18 +-- migration/bson2json.py | 2 +- migration/export.py | 4 +- migration/extract.py | 2 +- migration/tables/comments.py | 4 +- migration/tables/content_items.py | 6 +- migration/tables/topics.py | 4 +- migration/tables/users.py | 4 +- nginx.conf | 180 ++++++++++++++++++++++++++++ 10 files changed, 203 insertions(+), 22 deletions(-) delete mode 100644 migration/__init__.py rename migrate.py => migration/__main__.py (94%) create mode 100644 nginx.conf diff --git a/migration/__init__.py b/migration/__init__.py deleted file mode 100644 index e2750039..00000000 --- a/migration/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__all__ = ["tables", "bson2json", "html2md"] \ No newline at end of file diff --git a/migrate.py b/migration/__main__.py similarity index 94% rename from migrate.py rename to migration/__main__.py index c5312a3a..f20b2ced 100644 --- a/migrate.py +++ b/migration/__main__.py @@ -5,17 +5,19 @@ import subprocess import sys import os -# from migration.export import export_email_subscriptions -from migration.export import export_mdx, export_slug -from migration.tables.users import migrate as migrateUser -from migration.tables.users import migrate_2stage as migrateUser_2stage -from migration.tables.content_items import get_shout_slug, migrate as migrateShout -from migration.tables.topics import migrate as migrateTopic -from migration.tables.comments import migrate as migrateComment -from migration.tables.comments import migrate_2stage as migrateComment_2stage +# from export import export_email_subscriptions +from export import export_mdx, export_slug from orm.reaction import Reaction +from tables.users import migrate as migrateUser +from tables.users import migrate_2stage as migrateUser_2stage +from tables.content_items import get_shout_slug, migrate as migrateShout +from tables.topics import migrate as migrateTopic +from tables.comments import migrate as migrateComment +from tables.comments import migrate_2stage as migrateComment_2stage + from settings import DB_URL + TODAY = datetime.strftime(datetime.now(), '%Y%m%d') OLD_DATE = '2016-03-05 22:22:00.350000' diff --git a/migration/bson2json.py b/migration/bson2json.py index ba2802db..5c48c936 100644 --- a/migration/bson2json.py +++ b/migration/bson2json.py @@ -2,7 +2,7 @@ import os import bson import json -from migration.utils import DateTimeEncoder +from utils import DateTimeEncoder def json_tables(): print('[migration] unpack dump/discours/*.bson to migration/data/*.json') diff --git a/migration/export.py b/migration/export.py index d4463aa8..8d47b8ce 100644 --- a/migration/export.py +++ b/migration/export.py @@ -3,8 +3,8 @@ from datetime import datetime import json import os import frontmatter -from migration.extract import extract_html, prepare_html_body -from migration.utils import DateTimeEncoder +from extract import extract_html, prepare_html_body +from utils import DateTimeEncoder OLD_DATE = '2016-03-05 22:22:00.350000' EXPORT_DEST = '../discoursio-web/data/' diff --git a/migration/extract.py b/migration/extract.py index c8220609..eaef6a6c 100644 --- a/migration/extract.py +++ b/migration/extract.py @@ -1,7 +1,7 @@ import os import re import base64 -from migration.html2text import html2text +from html2text import html2text TOOLTIP_REGEX = r'(\/\/\/(.+)\/\/\/)' contentDir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'discoursio-web', 'content') diff --git a/migration/tables/comments.py b/migration/tables/comments.py index d1147d7a..d4294a1f 100644 --- a/migration/tables/comments.py +++ b/migration/tables/comments.py @@ -2,8 +2,8 @@ from datetime import datetime from dateutil.parser import parse as date_parse from orm import Reaction, User from orm import reaction -from orm.base import local_session -from migration.html2text import html2text +from base.orm import local_session +from html2text import html2text from orm.reaction import ReactionKind from orm.shout import Shout diff --git a/migration/tables/content_items.py b/migration/tables/content_items.py index c5f85840..78d9f7db 100644 --- a/migration/tables/content_items.py +++ b/migration/tables/content_items.py @@ -1,11 +1,11 @@ from dateutil.parser import parse as date_parse import sqlalchemy from orm.shout import Shout, ShoutTopic, User -from storages.viewed import ViewedByDay +from services.stat.viewed import ViewedByDay from transliterate import translit from datetime import datetime -from orm.base import local_session -from migration.extract import prepare_html_body +from base.orm import local_session +from extract import prepare_html_body from orm.community import Community from orm.reaction import Reaction, ReactionKind diff --git a/migration/tables/topics.py b/migration/tables/topics.py index 57084ecb..890034eb 100644 --- a/migration/tables/topics.py +++ b/migration/tables/topics.py @@ -1,5 +1,5 @@ -from migration.extract import extract_md, html2text -from orm.base import local_session +from extract import extract_md, html2text +from base.orm import local_session from orm import Topic, Community def migrate(entry): diff --git a/migration/tables/users.py b/migration/tables/users.py index 40b0eaf4..5aa17d9e 100644 --- a/migration/tables/users.py +++ b/migration/tables/users.py @@ -1,8 +1,8 @@ import sqlalchemy -from migration.html2text import html2text +from html2text import html2text from orm import User, UserRating from dateutil.parser import parse -from orm.base import local_session +from base.orm import local_session def migrate(entry): if 'subscribedTo' in entry: del entry['subscribedTo'] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..635a17de --- /dev/null +++ b/nginx.conf @@ -0,0 +1,180 @@ + +#user nobody; +worker_processes 1; + +#error_log logs/error.log; +#error_log logs/error.log notice; +error_log error.log info; + +#pid logs/nginx.pid; + + +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + + #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 0; + keepalive_timeout 65; + + #gzip on; + + map $http_origin $allow_origin { + ~^https?://(.*\.)?localhost:3000|new.discours.io|discours.io()(:\d+)?$ $http_origin; + default ""; + } + + upstream discoursio-api-8080 { + server 0.0.0.0:8080; + } + + server { + listen localhost:8000; + #server_name localhost; + #charset koi8-r; + # access_log logs/host.access.log main; + + #location / { + # root html; + # index index.html index.htm; + #} + + location / { + gzip on; + gzip_min_length 1100; + gzip_buffers 4 32k; + gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml; + gzip_vary on; + gzip_comp_level 6; + + proxy_pass http://discoursio-api-8080; + http2_push_preload on; + proxy_http_version 1.1; + proxy_read_timeout 60s; + proxy_buffer_size 4096; + proxy_buffering on; + proxy_buffers 8 4096; + proxy_busy_buffers_size 8192; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $http_connection; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Port $server_port; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Request-Start $msec; + + + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + # + # Custom headers and headers various browsers *should* be OK with but aren't + # + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + add_header 'Access-Control-Allow-Credentials' 'true'; + # + # Tell client that this pre-flight info is valid for 20 days + # + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain; charset=utf-8'; + add_header 'Content-Length' 0; + return 204; + } + + if ($request_method = 'POST') { + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; + add_header 'Access-Control-Allow-Credentials' 'true' always; + } + + if ($request_method = 'GET') { + add_header 'Access-Control-Allow-Origin' '*:' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; + add_header 'Access-Control-Allow-Credentials' 'true' always; + } + } + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + + + # another virtual host using mix of IP-, name-, and port-based configuration + # + #server { + # listen 8000; + # listen somename:8080; + # server_name somename alias another.alias; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + + + # HTTPS server + # + #server { + # listen 443 ssl; + # server_name localhost; + + # ssl_certificate cert.pem; + # ssl_certificate_key cert.key; + + # ssl_session_cache shared:SSL:1m; + # ssl_session_timeout 5m; + + # ssl_ciphers HIGH:!aNULL:!MD5; + # ssl_prefer_server_ciphers on; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + include servers/*; +} \ No newline at end of file