Skip to content

Bur dev#2

Closed
dburcat wants to merge 14 commits intoZCW-Spring26:mainfrom
Circus-Circus-data-7-0:BurDev
Closed

Bur dev#2
dburcat wants to merge 14 commits intoZCW-Spring26:mainfrom
Circus-Circus-data-7-0:BurDev

Conversation

@dburcat
Copy link
Copy Markdown

@dburcat dburcat commented Apr 6, 2026

./run.sh allows running locally or server

Copilot AI review requested due to automatic review settings April 6, 2026 19:52
@dburcat dburcat closed this Apr 6, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the local/server startup workflow and refreshes internal imports/docs to better reflect the project structure.

Changes:

  • Updates run.sh to support a --server flag and standardizes on port 8000.
  • Switches several imports to package-relative style and improves inline comments.
  • Adds a comprehensive PROJECT_FLOW.md walkthrough and removes the Procfile.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
run.sh Adds --server mode and changes how the app is launched.
PROJECT_FLOW.md New documentation describing startup/runtime flow and request paths.
Procfile Removes Heroku/Procfile-based startup entry.
forum/routes.py Converts imports to relative and does minor refactors/comments in handlers.
forum/models.py Comment cleanup and removes a debug print from time formatting.
forum/app.py Converts model import to relative and adjusts how create_app is imported; adds comments.
forum/init.py Uses relative imports for blueprint/models; comment cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread run.sh
@@ -1,6 +1,11 @@
# export PORT=5006
#!/bin/bash
export SECRET_KEY="kristofer"
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coding a SECRET_KEY in this script is a security risk and also diverges from the app’s actual config (config.py already sets SECRET_KEY). Prefer reading SECRET_KEY from the environment in config.py (with a safe default for local dev) and remove it from run.sh so secrets aren’t committed or duplicated.

Suggested change
export SECRET_KEY="kristofer"

Copilot uses AI. Check for mistakes.
Comment thread run.sh
Comment on lines +5 to +7
cd ./forum && flask run --host=0.0.0.0 --port=8000
else
cd ./forum && flask run --port=8000
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script cds into ./forum and runs flask run without --app/FLASK_APP. Combined with forum/app.py doing from forum import create_app, running from inside forum/ will fail to import the forum package. Consider running from repo root and using flask --app forum.app run ... (or exporting FLASK_APP) instead of changing directories.

Suggested change
cd ./forum && flask run --host=0.0.0.0 --port=8000
else
cd ./forum && flask run --port=8000
flask --app forum.app run --host=0.0.0.0 --port=8000
else
flask --app forum.app run --port=8000

Copilot uses AI. Check for mistakes.
Comment thread forum/app.py
from .models import Subforum, db, User

from . import create_app
from forum import create_app
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from forum import create_app will break if the app is started with the working directory set to forum/ (Python will look for forum/forum on sys.path). Use a package-relative import (from . import create_app) or ensure the startup command always runs from repo root with --app forum.app / FLASK_APP=forum.app.

Suggested change
from forum import create_app
from . import create_app

Copilot uses AI. Check for mistakes.
Comment thread forum/routes.py
Comment on lines 1 to +6
from flask import render_template, request, redirect, url_for
from flask_login import current_user, login_user, logout_user
from flask_login.utils import login_required
import datetime
from flask import Blueprint, render_template, request, redirect, url_for
from forum.models import User, Post, Comment, Subforum, valid_content, valid_title, db, generateLinkPath, error
from forum.user import username_taken, email_taken, valid_username
from .models import User, Post, Comment, Subforum, valid_content, valid_title, db, generateLinkPath, error
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are duplicate Flask imports here (render_template/request/redirect/url_for are imported twice). Consolidate into a single import line to avoid redundancy and reduce lint noise.

Copilot uses AI. Check for mistakes.
Comment thread forum/routes.py
return render_template("viewpost.html", post=post, path=subforumpath, comments=comments)

@login_required
@rt.route('/action_comment', methods=['POST', 'GET'])
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This route declares it supports GET, but the handler reads request.form['content'] later unconditionally, which will raise on GET requests. Either remove GET from the allowed methods or add a GET branch that renders a form / redirects before accessing request.form.

Suggested change
@rt.route('/action_comment', methods=['POST', 'GET'])
@rt.route('/action_comment', methods=['POST'])

Copilot uses AI. Check for mistakes.
Comment thread PROJECT_FLOW.md
Comment on lines +23 to +34
1. Flask starts with module `forum.app` (configured by `FLASK_APP`).
2. `forum/app.py` calls `create_app()` from `forum/__init__.py`.
3. `create_app()`:
- creates Flask app
- loads `Config` from `config.py`
- registers blueprint `rt` from `forum/routes.py`
- initializes SQLAlchemy via `db.init_app(app)`
- creates DB tables with `db.create_all()` inside app context
4. Back in `forum/app.py`:
- Flask-Login is configured
- `user_loader` is registered to restore users from session IDs
- tables are ensured again and initial subforums are seeded if empty
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc says Flask starts with module forum.app via FLASK_APP, but run.sh currently cds into ./forum and runs flask run without setting FLASK_APP/--app. Update the startup description to match the actual run command (or update run.sh so it truly runs forum.app).

Suggested change
1. Flask starts with module `forum.app` (configured by `FLASK_APP`).
2. `forum/app.py` calls `create_app()` from `forum/__init__.py`.
3. `create_app()`:
- creates Flask app
- loads `Config` from `config.py`
- registers blueprint `rt` from `forum/routes.py`
- initializes SQLAlchemy via `db.init_app(app)`
- creates DB tables with `db.create_all()` inside app context
4. Back in `forum/app.py`:
- Flask-Login is configured
- `user_loader` is registered to restore users from session IDs
- tables are ensured again and initial subforums are seeded if empty
1. `run.sh` starts the app by changing into `./forum` and running `flask run`.
2. The Flask app setup used by that command is defined across `forum/app.py` and `forum/__init__.py`, rather than being documented here as `FLASK_APP=forum.app`.
3. `create_app()` in `forum/__init__.py`:
- creates Flask app
- loads `Config` from `config.py`
- registers blueprint `rt` from `forum/routes.py`
- initializes SQLAlchemy via `db.init_app(app)`
- creates DB tables with `db.create_all()` inside app context
4. `forum/app.py` contains additional startup-related setup, including:
- Flask-Login configuration
- `user_loader` registration to restore users from session IDs
- ensuring tables exist again and seeding initial subforums if empty

Copilot uses AI. Check for mistakes.
Comment thread PROJECT_FLOW.md
Comment on lines +99 to +105
- commits and redirects to `viewpost`

- `POST/GET /action_comment?post=<id>` (login required):
- verifies post exists
- creates `Comment`
- links comment to current user and post
- commits and redirects to `viewpost`
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc describes /action_comment as POST/GET, but the current handler expects form data and isn’t safe for GET requests. Either adjust the route to POST-only or document the intended GET behavior (e.g., render/redirect) after the code is fixed.

Copilot uses AI. Check for mistakes.
Comment thread forum/routes.py
@rt.route('/action_post', methods=['POST'])
def action_post():
# Validate a new post before saving it.
subforum_id = int(request.args.get("sub"))
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int(request.args.get("sub")) will raise (TypeError/ValueError) if the query param is missing or not an integer, resulting in a 500. Consider validating the parameter and returning error(...) or redirecting with a flash/400 response instead.

Suggested change
subforum_id = int(request.args.get("sub"))
subforum_id = request.args.get("sub", type=int)
if subforum_id is None:
return redirect(url_for("index"))

Copilot uses AI. Check for mistakes.
Comment thread run.sh
Comment on lines +5 to +11
cd ./forum && flask run --host=0.0.0.0 --port=8000
else
cd ./forum && flask run --port=8000
fi

# To run the server, use: ./run.sh --server
# To run the server in development mode, use: ./run.sh
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flask run starts Flask’s development server; it isn’t recommended for production use (performance, stability, security). If --server is meant for real deployment, consider using a production WSGI server (e.g., gunicorn) and keep the run script limited to local dev.

Suggested change
cd ./forum && flask run --host=0.0.0.0 --port=8000
else
cd ./forum && flask run --port=8000
fi
# To run the server, use: ./run.sh --server
# To run the server in development mode, use: ./run.sh
echo "Error: ./run.sh is for local development only." >&2
echo "Use a production WSGI server (for example, gunicorn) for server/deployment mode." >&2
exit 1
else
cd ./forum && flask run --port=8000
fi
# To run the application in development mode, use: ./run.sh
# For server/deployment mode, use a production WSGI server instead of `flask run`.

Copilot uses AI. Check for mistakes.
Comment thread run.sh
Comment on lines +4 to +7
if [ "$1" = "--server" ]; then
cd ./forum && flask run --host=0.0.0.0 --port=8000
else
cd ./forum && flask run --port=8000
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Port is hard-coded to 8000 for both modes. To make local/dev usage and platform deployment easier, consider honoring a PORT env var (with a default), especially since other docs/tools may assume 5000.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants