Add initial backend implementation and project configuration files
This commit is contained in:
50
main.bk
Normal file
50
main.bk
Normal file
@@ -0,0 +1,50 @@
|
||||
from flask import Flask, request, jsonify
|
||||
from flask_cors import CORS
|
||||
|
||||
app = Flask(__name__, static_folder="../front-end/dist/assets", template_folder="../front-end/dist")
|
||||
CORS(app)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return app.send_static_file('index.html')
|
||||
|
||||
# Essential for handling client-side routing (e.g., Vue Router history mode)
|
||||
@app.route('/<path:path>')
|
||||
def static_files(path):
|
||||
return app.send_static_file(path)
|
||||
|
||||
@app.route('/api/set', methods=['POST'])
|
||||
def handle_json_data():
|
||||
data = request.get_json()
|
||||
|
||||
if not data:
|
||||
return jsonify({'error': 'Missing JSON data'}), 400
|
||||
|
||||
if 'lat' not in data:
|
||||
return jsonify({'error': 'Missing lat in JSON data'}), 400
|
||||
|
||||
if 'lng' not in data:
|
||||
return jsonify({'error': 'Missing lng in JSON data'}), 400
|
||||
|
||||
# Process the data (e.g., save to a database)
|
||||
lat = data['lat']
|
||||
lng = data['lng']
|
||||
|
||||
# Return a JSON response
|
||||
return jsonify({
|
||||
'message': f'lat: {lat}, lng: {lng} received successfully!',
|
||||
'data': data
|
||||
}), 200
|
||||
|
||||
@app.route('/api/status', methods=['GET'])
|
||||
def get_data():
|
||||
return jsonify(message="Hello from Flask API!")
|
||||
|
||||
@app.errorhandler(404)
|
||||
def not_found(error):
|
||||
return jsonify({'error': 'Not found'}), 404
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port=5000)
|
||||
Reference in New Issue
Block a user