Skip to content

Instantly share code, notes, and snippets.

@cristianvasquez
Created April 28, 2021 10:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristianvasquez/6b8a13d6452b7600a64b4e554939e052 to your computer and use it in GitHub Desktop.
Save cristianvasquez/6b8a13d6452b7600a64b4e554939e052 to your computer and use it in GitHub Desktop.
Opl hello world example
from flask import Flask, request
from flask_cors import CORS
####################################################################################
# config
####################################################################################
PORT = 5000
HOST = '127.0.0.1'
app = Flask(__name__)
####################################################################################
# Cors
####################################################################################
# Allows access to fetch at 'http://localhost:5000/' from origin 'app://obsidian.md'
obsidian_origin = "app://obsidian.md"
cors = CORS(app, origins=obsidian_origin)
app.config['CORS_HEADERS'] = 'Content-Type'
####################################################################################
# Routers
####################################################################################
'''Return a list of all detected plugins'''
@app.route('/', methods=['GET'])
def root():
return {
'scripts': [
f'http://{HOST}:{PORT}/hello'
]
}
'''
The operation
'''
@app.route('/hello', methods=['POST'])
def run():
note_path = request.json['notePath']
vault_path = request.json['vaultPath']
return {
'contents': f'Hello, note {note_path} in vault {vault_path}'
}
def main():
app.run(port=PORT, host=HOST)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment