Exemplo n.º 1
0
def configure_application(services: Container,
                          context: ServicesRegistrationContext,
                          configuration: Configuration):
    app = Application(services=services,
                      show_error_details=configuration.show_error_details,
                      debug=configuration.debug)

    app.on_start += context.initialize
    app.on_stop += context.dispose

    configure_error_handlers(app)
    configure_authentication(app)
    configure_templating(app, configuration)

    app.serve_files('app/static')

    return app
Exemplo n.º 2
0
import io
import uvicorn
import asyncio
from blacksheep import Request, Response, Content, Cookie
from blacksheep.server import Application
from blacksheep.server.responses import text, json, file, ContentDispositionType
from blacksheep.server.bindings import FromQuery
from itests.utils import CrashTest, ensure_folder

app = Application(show_error_details=True)

app.serve_files('static', discovery=True)


@app.route('/hello-world')
async def hello_world():
    return text(f'Hello, World!')


@app.router.head('/echo-headers')
async def echo_headers(request):
    response = Response(200)

    for header in request.headers:
        response.add_header(header[0], header[1])

    return response


@app.route('/echo-cookies')
async def echo_cookies(request):
Exemplo n.º 3
0
from blacksheep.server.bindings import FromQuery
from blacksheep.server.files import ServeFilesOptions
from blacksheep.server.responses import ContentDispositionType, file, json, text
from itests.utils import CrashTest, ensure_folder

app = Application(show_error_details=True)

static_folder_path = pathlib.Path(__file__).parent.absolute() / "static"


def get_static_path(file_name):
    static_folder_path = pathlib.Path(__file__).parent.absolute() / "static"
    return os.path.join(str(static_folder_path), file_name)


app.serve_files(ServeFilesOptions(static_folder_path, discovery=True))


@app.route("/hello-world")
async def hello_world():
    return text(f"Hello, World!")


@app.router.head("/echo-headers")
async def echo_headers(request):
    response = Response(200)

    for header in request.headers:
        response.add_header(header[0], header[1])

    return response
Exemplo n.º 4
0
        'risk': event_risk(evt, len(evt.seats))
    })


@post('/join-event-endpoint')
async def join_event_post(request: Request):
    js = await request.json()
    seat = js['seat_number']
    _id = js['id']
    evt = db.load_event(_id)
    for i, s_o in enumerate(evt.seats):
        if s_o['number'] == seat:
            evt.seats[i]['occupied'] = True
    db.store_event(evt)
    return status_code(200, 'success')


@get('/event-joined')
def event_joined(id: str):
    evt = db.load_event(id)
    return view('event-joined', {
        'event': evt,
        'risk': event_risk(evt, len(evt.seats))
    })


app.serve_files('static')

if __name__ == '__main__':
    uvicorn.run(app, host='0.0.0.0', port=42069)
Exemplo n.º 5
0
from blacksheep.server.bindings import FromQuery
from blacksheep.server.responses import ContentDispositionType, file, json, text
from itests.utils import CrashTest, ensure_folder

app = Application(show_error_details=True)


static_folder_path = pathlib.Path(__file__).parent.absolute() / "static"


def get_static_path(file_name):
    static_folder_path = pathlib.Path(__file__).parent.absolute() / "static"
    return os.path.join(str(static_folder_path), file_name)


app.serve_files(static_folder_path, discovery=True)


@app.route("/hello-world")
async def hello_world():
    return text(f"Hello, World!")


@app.router.head("/echo-headers")
async def echo_headers(request):
    response = Response(200)

    for header in request.headers:
        response.add_header(header[0], header[1])

    return response