Add a trivial stub web service

This commit is contained in:
Danny Robson 2020-06-09 14:34:22 +10:00
parent 30a7e223c3
commit b7e9d6a351
4 changed files with 64 additions and 0 deletions

View File

@ -1,3 +1,7 @@
alembic
sqlalchemy
dateparser
TurboGears2
kajiki
webhelpers2

52
src/www/serve.py Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env python3
import tg
import tg.util
import tg.configurator.components.sqlalchemy
import sqlalchemy as sa
import sqlalchemy.orm
class RootController(tg.TGController):
@tg.expose('templates/index.xhtml')
def index(self, person=None):
return dict(person=person)
config = tg.MinimalApplicationConfigurator()
config.register(tg.configurator.components.sqlalchemy.SQLAlchemyConfigurationComponent)
config.update_blueprint({
'serve_static': True,
'paths': {
'static_files': 'static'
},
'root_controller': RootController(),
'renderers': ['kajiki'],
'helpers': 'webhelpers2',
'use_sqlalchemy': True,
'sqlalchemy.url': 'sqlite:///../../db/data.sqlite'
})
DBSession = sqlalchemy.orm.scoped_session(
sqlalchemy.orm.sessionmaker(autoflush=True, autocommit=False)
)
def init_model(engine):
DBSession.configure(bind=engine)
config.update_blueprint({
'model': tg.util.Bunch(
DBSession=DBSession,
init_model=init_model,
)
})
application = config.make_wsgi_app()
import wsgiref.simple_server
print ("Serving on 8080")
httpd = wsgiref.simple_server.make_server('', 8080, application)
httpd.serve_forever()

0
src/www/static/.keep Normal file
View File

View File

@ -0,0 +1,8 @@
<html>
<title>Hello</title>
<py:if test="person">
<h1>Hello ${person}</h1>
</py:if><py:else>
<h1>Hello World!</h1>
</py:else>
</html>