mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Now serving static/index.html on :8000
This commit is contained in:
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
class Config:
|
||||
"""Main System Configuration"""
|
||||
def __init__(self):
|
||||
self.book_path = "/home/raelon/Books/"
|
||||
self.book_path = "books/"
|
||||
self.book_shelf = "data/shelf.json"
|
||||
self.catalogue_db = "data/catalogue.db"
|
||||
self.file_array = [
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
|
||||
raelon@golumnsec.6371:1572529288
|
||||
@@ -1,10 +1,12 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
import zipfile
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
from config import Config
|
||||
from lib.library import Catalogue
|
||||
from lib.storage import Storage
|
||||
|
||||
config = Config()
|
||||
Storage = Storage()
|
||||
|
||||
@@ -16,6 +18,7 @@ class InitFiles:
|
||||
for _pointer in file_array:
|
||||
if not os.path.isfile(_pointer):
|
||||
self.CreateFile(_pointer)
|
||||
print("Concluded file creation")
|
||||
|
||||
def CreateFile(self, _pointer):
|
||||
"""Create the file"""
|
||||
@@ -28,14 +31,21 @@ class InitFiles:
|
||||
class RequestHandler(BaseHTTPRequestHandler):
|
||||
"""Request Handler"""
|
||||
def do_GET(self):
|
||||
# TODO determine how to include stylesheets
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(b'Welcome To pyShelf!')
|
||||
|
||||
if self.path == '/':
|
||||
self.path = '../static/index.html'
|
||||
serve_file = open(self.path[1:]).read()
|
||||
else:
|
||||
self.send_response(404)
|
||||
serve_file = "File Not Found"
|
||||
self.wfile.write(bytes(serve_file, 'utf-8'))
|
||||
|
||||
class BookServer:
|
||||
"""HTTP Frontend"""
|
||||
def __init__(self):
|
||||
# TODO Get server Ip Address
|
||||
self.server_address = ('', 8000)
|
||||
self.handler = RequestHandler
|
||||
|
||||
@@ -52,13 +62,13 @@ class BookServer:
|
||||
"""Start HTTP Server"""
|
||||
self.httpd = HTTPServer(self.server_address, self.handler)
|
||||
try:
|
||||
print("Server running @ http://127.0.0.1:8000")
|
||||
self.httpd.serve_forever()
|
||||
self.httpd.handle_request()
|
||||
if self.close_prompt() == True:
|
||||
pass
|
||||
except KeyboardInterrupt:
|
||||
print(KeyboardInterrupt, " Closing Server")
|
||||
print("Interrupt received, Closing Server")
|
||||
self.close()
|
||||
print("Server shutdown, Goodbye!")
|
||||
return False
|
||||
|
||||
def close(self):
|
||||
@@ -68,4 +78,3 @@ class BookServer:
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
3
static/css/main.css
Normal file
3
static/css/main.css
Normal file
@@ -0,0 +1,3 @@
|
||||
body{
|
||||
background-color: #f1f1
|
||||
}
|
||||
16
static/index.html
Normal file
16
static/index.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link type="text/css" rel="stylesheet" href="/css/main.css" />
|
||||
<title>pyShelf E-Book Server</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<h1 class="app_hdr">Welcome to pyShelf</h1>
|
||||
<h2 class="app_subhdr">An Open Source E-book Server!</h2>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user