Skip to content

Commit

Permalink
前端页面用fastapi运行,不再使用nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
jan committed Nov 17, 2020
1 parent 36a8edf commit ea4be34
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import sqlite3
import hashlib
from fastapi import FastAPI, File, UploadFile, Body,Query, HTTPException, Depends, status
from fastapi.middleware.gzip import GZipMiddleware
from fastapi.staticfiles import StaticFiles
from starlette.responses import FileResponse
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
import jwt
from jwt import PyJWTError
Expand Down Expand Up @@ -54,6 +57,9 @@ class UserInDB(User):
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/login")

app= FastAPI()
app.mount("/static", StaticFiles(directory="dist/static"), name="static")
app.add_middleware(GZipMiddleware, minimum_size=1000)


#用户登录验证和token方法集:
def verify_password(plain_password, hashed_password):
Expand Down Expand Up @@ -185,6 +191,10 @@ def get_client_port(client_ip) ->str:
return config_ini.get('client',client_ip)


@app.get("/")
async def get_index():
return FileResponse('dist/index.html')

#response_model=Token
@app.post("/login")
async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
Expand Down

0 comments on commit ea4be34

Please sign in to comment.