Hey, Iβm having related issues @simply-zaki and @pawlean
And Iβm an experienced data engineer but very new to anything that touches front end, especially making front end and backend talk to each other.
Iβve got my app working locally, with flask and svelte both spun up in different terminals, and Iβve got it deployed and running without 404, but I canβt get my app to talk to each other, getting 500 errors, and it seems like my flask app isnβt receiving anything.
This seems similar enough to my issue that it would be best to add a comment, but happy to make a seperate post.
How can I fix this, or at least can I confirm that flask is running in vercel?
I want to run svelte, flask, with a sqlite db. Also, let me know if this is even a sensible thing to do.
Here is my project structure
βββ README.md
βββ __pycache__
β βββ config.cpython-39.pyc
βββ app
β βββ __init__.py
β βββ __pycache__
β β βββ __init__.cpython-39.pyc
β β βββ models.cpython-39.pyc
β β βββ schemas.cpython-39.pyc
β βββ models.py
β βββ routes
β β βββ __init__.py
β β βββ __pycache__
β β βββ drills.py
β β βββ practice_plans.py
β βββ schemas.py
βββ config.py
βββ cypress
β βββ downloads
β βββ e2e
β β βββ drill_creation.cy.js
β βββ fixtures
β β βββ example.json
β βββ support
β βββ commands.ts
β βββ e2e.ts
βββ cypress.config.js
βββ instance
β βββ app.db
βββ jsconfig.json
βββ migrations
β βββ README
β βββ __pycache__
β β βββ env.cpython-39.pyc
β βββ alembic.ini
β βββ env.py
β βββ script.py.mako
β βββ versions
β βββ __pycache__
β βββ d619d994ebdc_.py
βββ package-lock.json
βββ package.json
βββ playwright.config.js
βββ pnpm-lock.yaml
βββ requirements.txt
βββ src
β βββ app.d.ts
β βββ app.html
β βββ lib
β β βββ images
β β βββ vitals.js
β βββ routes
β βββ +layout.server.js
β βββ +layout.svelte
β βββ +page.js
β βββ +page.svelte
β βββ Counter.svelte
β βββ Header.svelte
β βββ api
β βββ drills
β βββ practice-plans
β βββ styles.css
βββ static
β βββ favicon.png
β βββ robots.txt
βββ svelte.config.js
βββ tests
β βββ test.js
β βββ test_api.py
βββ tsconfig.json
βββ vercel.json
βββ vite.config.js
Here are some file snippets:
app/init.py
app = Flask(__name__)
app.config.from_object('config.Config')
db = SQLAlchemy(app)
ma = Marshmallow(app)
migrate = Migrate(app, db)
CORS(app)
from app.routes.drills import drills_bp
from app.routes.practice_plans import practice_plans_bp
app.register_blueprint(drills_bp, url_prefix='/api/drills')
app.register_blueprint(practice_plans_bp, url_prefix='/api/practice-plans')
app/routes/init.py
(Some duplication here, but shouldnβt cause issues, and doesnβt locally)
from flask import Blueprint
main_bp = Blueprint('main', __name__)
def register_blueprints(app):
from app.routes.drills import drills_bp
from app.routes.practice_plans import practice_plans_bp
app.register_blueprint(drills_bp, url_prefix='/api/drills')
app.register_blueprint(practice_plans_bp, url_prefix='/api/practice-plans')
app/routes/drills.py
drills_bp = Blueprint('drills', __name__)
@drills_bp.route('/', methods=['POST'])
def create_drill():
and
vercel.json
{
"rewrites": [
{ "source": "/api/drills/(.*)", "destination": "/api/drills" },
{ "source": "/api/practice-plans/(.*)", "destination": "/api/practice-plans" }
]
}
And Iβm getting 500 errors whenever I try to use the flask backend.
Error occurred while sending request: TypeError: fetch failed
at node:internal/deps/undici/undici:13178:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async POST (file:///var/task/.svelte-kit/output/server/entries/endpoints/api/drills/_server.js:9:22)
at async render_endpoint (file:///var/task/.svelte-kit/output/server/index.js:214:20)
at async resolve2 (file:///var/task/.svelte-kit/output/server/index.js:3495:22)
at async respond (file:///var/task/.svelte-kit/output/server/index.js:3384:22)
at async Server.default (file:///var/task/.svelte-kit/vercel-tmp/index.js:47:3)
at async Server.<anonymous> (/opt/rust/nodejs.js:8:4242) {
[cause]: Error: connect ECONNREFUSED 127.0.0.1:5000
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5000
}
}