def index(): return response([ ''' <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> </head> <body> <input id='username' type='text' /> <input id='password' type='password' /> <button id='submit'>Login</button> <script> $(document).ready(function() { $('#submit').click(function() { $.ajax({ dataType: "json", url: '/login', method: 'POST', contentType: 'application/json', data: JSON.stringify({ username: $('#username').val(), password: $('#password').val() }), success: function() { console.log('done', arguments); window.location = '/profile'; }, error: function(data) { alert('login error'); } }); }); }); </script> </body> </html> '''.strip() ], mimetype='text/html')
def home(x): text = f''' <!DOCTYPE html> <html> <head> </head> <body> <center> <h1>Welcome to Module</h1> <h2>x is {x}</h2> <a href='{request.path}/protected'>protected page</a> <a href='module.json'>module info</a> <hr> <a href='..'>back</a> </center> </body> </html ''' return response([text], mimetype='text/html')
def home(x): text = f''' <!DOCTYPE html> <html> <head> </head> <body> <center> <h1>Welcome to Madness</h1> <h2>x is {x}</h2> <a href='throw'>raise api exception</a> <a href='invalid-route'>404 page</a> <a href='relative/path'>relative path!</a> <hr> <a href='module'>module</a> </center> </body> </html ''' return response([text], mimetype='text/html')
def profile(username): return response( ['welcome back, ', username, '<br /><a href=/logout>logout</a>'], mimetype='text/html')
def crossdomain(): return response(['from anywhere!'])
def mypath(): return response(['wow!!'])
def my404(): return response(['not found!!'])
def response(obj, **kwargs): return madness.response( [json.dumps(obj)], mimetype = 'application/json; charset=utf-8', **kwargs )
def greet(username): return response([f'welcome back, {username}'])