Serve the html
This commit is contained in:
		
							parent
							
								
									78848e062f
								
							
						
					
					
						commit
						8308109bb1
					
				
							
								
								
									
										4
									
								
								api.py
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								api.py
									
									
									
									
									
								
							@ -1,13 +1,15 @@
 | 
			
		||||
from fastapi import FastAPI, Response
 | 
			
		||||
from fastapi.responses import RedirectResponse
 | 
			
		||||
from fastapi.staticfiles import StaticFiles
 | 
			
		||||
import couchdb
 | 
			
		||||
import uuid
 | 
			
		||||
 | 
			
		||||
app = FastAPI()
 | 
			
		||||
app.mount("/", StaticFiles(directory="client", html=True), name="client")
 | 
			
		||||
 | 
			
		||||
couch = couchdb.Server("http://admin:password@127.0.0.1:5984")
 | 
			
		||||
 | 
			
		||||
@app.get("/{url_id}", status_code=301)
 | 
			
		||||
@app.get("/{url_id}", status_code=301, response_class=RedirectResponse)
 | 
			
		||||
async def redirect_urls(url_id):
 | 
			
		||||
    target_url = couch["urls"][url_id].get('full_url')
 | 
			
		||||
    return RedirectResponse(target_url)
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,24 @@
 | 
			
		||||
body {
 | 
			
		||||
    background-color: #f0ead2;
 | 
			
		||||
    margin: 0;
 | 
			
		||||
    padding: 25px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
h1 {
 | 
			
		||||
    color: #6c584c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
p {
 | 
			
		||||
    color: #6c584c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
button {
 | 
			
		||||
    color: #6c584c;
 | 
			
		||||
    background-color: #adc178;
 | 
			
		||||
    padding: 9px;
 | 
			
		||||
    margin: 5px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
input {
 | 
			
		||||
    height: 30px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,4 @@
 | 
			
		||||
fastapi
 | 
			
		||||
uvicorn
 | 
			
		||||
couchdb
 | 
			
		||||
aiofiles
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user