Skip to content

Commit 8180583

Browse files
committed
Adding app.py (tornado) and hooking it up with copy-build-plugin
1 parent 08b7571 commit 8180583

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

app.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/python
2+
3+
__author__ = "Jeffrey Jose"
4+
5+
import sys, os
6+
import simplejson as json
7+
8+
import tornado.ioloop
9+
import tornado.web
10+
import tornado.options
11+
import tornado.websocket
12+
13+
tornado.options.define("port", default=8000, help="Run on the given port", type=int)
14+
15+
vueAppPath = os.path.abspath(os.path.dirname(__file__))
16+
17+
class Default(tornado.web.RequestHandler):
18+
'''
19+
If Tornado doesnt know what to do, let vue take care of the url.
20+
'''
21+
22+
def get(self, path):
23+
'''
24+
HTTP GET Method handler
25+
'''
26+
self.redirect('/#%s' % path, permanent = True)
27+
28+
29+
class IndexHandler(tornado.web.RequestHandler):
30+
'''
31+
Handler to serve the template/index.html
32+
'''
33+
def get(self):
34+
'''
35+
HTTP GET Method handler
36+
'''
37+
with open(vueAppPath + "/index.html", 'r') as file:
38+
self.write(file.read())
39+
40+
class StaticHandler(tornado.web.RequestHandler):
41+
'''
42+
Handler to serve everything inside static/ directory
43+
'''
44+
45+
def get(self):
46+
'''
47+
HTTP GET Method handler
48+
'''
49+
self.set_header('Content-Type', '')
50+
with open(vueAppPath + self.request.uri, 'r') as file:
51+
self.write(file.read())
52+
53+
handlers = [
54+
(r'/', IndexHandler),
55+
(r'/static/.*', StaticHandler),
56+
(r'/(.*)', Default), # When you visit a non-existant link
57+
]
58+
59+
60+
if __name__ == "__main__":
61+
62+
tornado.options.parse_command_line()
63+
64+
# Turn debug on to have Tornado restart when you change this file
65+
# Recommended when you're developing. Dont forget to remove it
66+
# when you put this in production
67+
#
68+
#app = tornado.web.Application(handlers, debug = True)
69+
#
70+
71+
app = tornado.web.Application(handlers)
72+
app.listen(tornado.options.options.port)
73+
74+
print 'Tornado has started at %s' % tornado.options.options.port
75+
tornado.ioloop.IOLoop.instance().start()

build/webpack.prod.conf.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var merge = require('webpack-merge')
66
var baseWebpackConfig = require('./webpack.base.conf')
77
var ExtractTextPlugin = require('extract-text-webpack-plugin')
88
var HtmlWebpackPlugin = require('html-webpack-plugin')
9+
var CopyWebpackPlugin = require('copy-webpack-plugin')
910
var env = config.build.env
1011

1112
var webpackConfig = merge(baseWebpackConfig, {
@@ -73,7 +74,11 @@ var webpackConfig = merge(baseWebpackConfig, {
7374
new webpack.optimize.CommonsChunkPlugin({
7475
name: 'manifest',
7576
chunks: ['vendor']
76-
})
77+
}),
78+
// For python files
79+
new CopyWebpackPlugin([
80+
{from: './app.py'}
81+
]),
7782
]
7883
})
7984

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"coffee-loader": "^0.7.2",
13+
"copy-webpack-plugin": "^4.0.1",
1314
"vue": "^2.1.0",
1415
"vue-router": "^2.1.1",
1516
"vuex": "^2.0.0"

0 commit comments

Comments
 (0)