示例#1
0
def creates_app():
    """Create the application

    Returns:
        [fastapi.FastAPI]: the main application
    """

    LOGGER.info("Create application %s", app_version.RELEASE)
    app = fastapi.FastAPI(version=app_version.RELEASE,
                          title=settings.PROJECT_NAME,
                          openapi_url="/api/%s/openapi.json" % core.PATH,
                          template_directory='templates')
    app.mount('/static',
              staticfiles.StaticFiles(directory='cnapps/static'),
              name='static')
    app.include_router(health.router)
    app.include_router(version.router)
    app.include_router(web.router)
    app.include_router(core.api_router, prefix="/api/%s" % core.PATH)
    app.add_middleware(starlette_prometheus.PrometheusMiddleware)
    app.add_route("/metrics/", starlette_prometheus.metrics)
    return app
示例#2
0
from typing import List

import fastapi
from fastapi import File, UploadFile
# from fastapi import responses
from starlette import responses

from starlette import staticfiles

import pkg_resources

app = fastapi.FastAPI()
app.mount(
    '/web',
    staticfiles.StaticFiles(
        directory=pkg_resources.resource_filename(__name__, 'app/_site')),
    name='web')
app.mount('/site',
          staticfiles.StaticFiles(directory=pkg_resources.resource_filename(
              __name__, 'app/_site'),
                                  html=True),
          name='site')


@app.get('/')
def main():
    htmlfile = pkg_resources.resource_string(__name__, 'app/_site/upload.html')
    return responses.HTMLResponse(htmlfile)


## Single file uploads
示例#3
0
 def add_static_files(self, path, dir):
     self.router.mount(path, app=_staticfiles.StaticFiles(directory=dir))
import fastapi
from fastapi import Depends
# from fastapi import responses
from starlette import responses

# from fastapi import WebSocket
from starlette.websockets import WebSocket, WebSocketDisconnect
from starlette import staticfiles

from typing import Optional
import pkg_resources

from app.utils import fastapi_web_utils

app = fastapi.FastAPI()
app.mount('/web', staticfiles.StaticFiles(directory=pkg_resources.resource_filename(__name__, 'app/_site')), name='web')
app.mount('/site', staticfiles.StaticFiles(directory=pkg_resources.resource_filename(__name__, 'app/_site'), html = True), name='site')


@app.get('/')
def main():
  return {'message':'Web socket server using FastAPI'}


@app.get('/chat')
def chat():
  htmlfile = pkg_resources.resource_string(__name__, 'app/_site/websocket-1.html')
  return responses.HTMLResponse(htmlfile)


@app.get('/chat/{chati}')