penambahan base URL

main
ariwahyunahar 5 months ago
parent 84317e5b65
commit f09e7fb909

@ -12,6 +12,9 @@ import traceback
# Load environment variables from .env file
load_dotenv()
# Base URL configuration from environment variable, default to empty string if not set
BASE_URL = os.getenv("BASE_URL", "")
app = Flask(__name__)
# Database configuration from environment variables
@ -200,7 +203,7 @@ def analyze_data(df, part_info_df):
@app.route('/')
def index():
"""Render the main monitoring dashboard"""
return render_template('index.html')
return render_template('index.html', base_url=BASE_URL)
def fetch_part_history(part_id, days=14):
"""Fetch historical data for a specific part_id for the last 'days' days"""

@ -88,7 +88,7 @@ function fetchData(date) {
errorMessage.classList.add('d-none');
// Build the URL with date parameter if provided
let url = '/api/data';
let url = BASE_URL + '/api/data';
if (date) {
url += `?date=${encodeURIComponent(date)}`;
}
@ -315,7 +315,7 @@ function updateStatusCounts(redCount, yellowCount) {
* Fetch historical data for a specific part_id
*/
function fetchPartHistory(partId) {
return fetch(`/api/part-history?part_id=${encodeURIComponent(partId)}`)
return fetch(`${BASE_URL}/api/part-history?part_id=${encodeURIComponent(partId)}`)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');

@ -138,6 +138,10 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
// Pass base URL from Flask to JavaScript
const BASE_URL = "{{ base_url }}";
</script>
<script src="{{ url_for('static', filename='js/script.js') }}"></script>
</body>
</html>
Loading…
Cancel
Save