Skip to content
Browse files

Back to serveup solution and solved CORS

Signed-off-by: Wenwei Cai <stanley.w.cai@gmail.com>
  • Loading branch information...
1 parent 1c0caf8 commit 0aa6f82f55edc2f0bf7d7b070f73949466de2bde @swcai committed
Showing with 11 additions and 159 deletions.
  1. +1 −1 Procfile
  2. +0 −52 app.js
  3. +8 −7 app/models/stock.coffee
  4. +1 −7 package.json
  5. +0 −30 public/application.css
  6. +0 −1 public/application.js
  7. +1 −2 slug.json
  8. +0 −59 test/public/specs.js
View
2 Procfile
@@ -1 +1 @@
-web: node app.js
+web: serveup ./public
View
52 app.js
@@ -1,52 +0,0 @@
-var express = require('express')
-var app = express.createServer()
-
-// Reference
-// http://expressjs.com/guide.html
-// https://github.com/spadin/simple-express-static-server
-// http://devcenter.heroku.com/articles/node-js
-
-//CORS middleware
-var allowCrossDomain = function(req, res, next) {
- res.header('Access-Control-Allow-Origin', config.allowedDomains);
- res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
- res.header('Access-Control-Allow-Headers', 'Content-Type');
- next();
-}
-
-// Configuration
-app.configure(function(){
- app.use(express.static(__dirname + '/public'));
- app.use(express.bodyParser());
- app.use(express.methodOverride());
- app.use(allowCrossDomain);
- // LESS Support
- //app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }));
- // Template-enabled html view (by jade)
- // http://stackoverflow.com/questions/4529586/render-basic-html-view-in-node-js-express
- //app.set('views', __dirname + '/app/views');
- //app.register('.html', require('jade'));
-
- //Error Handling
- app.use(express.logger());
- app.use(express.errorHandler({
- dumpExceptions: true,
- showStack: true
- }));
-
- //Setup the Route, you are almost done
- app.use(app.router);
-});
-
-app.get('/', function(req, res){
- //Apache-like static index.html (public/index.html)
- res.redirect("/index.html");
- //Or render from view
- //res.render("index.html")
-});
-
-//Heroku
-var port = process.env.PORT || 80;
-app.listen(port, function() {
- console.log("Listening on " + port);
-});
View
15 app/models/stock.coffee
@@ -24,16 +24,17 @@ class Stock extends Spine.Model
@fetchPriceFromSite: (item) =>
return unless item
- console.log item
if item.code.charAt(0) == '6'
+ valname = 'sh' + item.code
url = @endpoint + 'sh' + item.code
else
+ valname = 'sz' + item.code
url = @endpoint + 'sz' + item.code
- console.log url
- $.get url, (data) =>
- left = data.indexOf '"'
- right = data.lastIndexOf '"'
- vals = (data.substring left + 1, right).split(",")
- item.updateAttributes(name: vals[0], currentPrice: vals[3])
+ $.ajaxSetup({cache: true})
+ $.getScript url, (data) =>
+ $.ajaxSetup({cache: false})
+ eval("data = hq_str_#{valname}")
+ vals = data.split(",")
+ item.updateAttributes(name: vals[0], currentPrice: vals[3])
module.exports = Stock
View
8 package.json
@@ -9,12 +9,6 @@
"jqueryify": "~0.0.1",
"spine": "~1.0.6",
"spine.mobile": "~1.0.0",
- "gfx": "~0.0.4",
- "express": "2.5.8",
- "jade": ">= 0.0.1"
- }
- , "engines": {
- "node": "0.6.13",
- "npm": "1.1.41"
+ "gfx": "~0.0.4"
}
}
View
30 public/application.css
@@ -1,30 +0,0 @@
-body,html{height:100%}
-.viewport{position:relative;}
-.viewport > *{position:absolute;left:0;right:0;top:0;bottom:0;}
-.viewport > *:not(.active){display:none}
-body.stage > header{position:absolute;left:0;top:0;right:0}
-body.stage > article{position:absolute;left:0;right:0;top:0;bottom:0}
-body.stage > footer{position:absolute;left:0;bottom:0;right:0}
-.panel{display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;}
-.panel > article{-webkit-box-flex:1;-moz-box-flex:1;box-flex:1;overflow:auto;-webkit-overflow-scrolling:touch}
-body{font-family:Helvetica Neue,Helvetica,Arial,sans-serif;overflow-x:hidden;-webkit-user-select:none;margin:0;padding:0;color:#292d39;background:#fff}
-*{-webkit-tap-highlight-color:rgba(0,0,0,0)}
-body.stage > header{height:40px;background:-webkit-gradient(linear,left top,left bottom,from(rgba(255,255,255,0.3)),color-stop(.5,rgba(255,255,255,0.1)),color-stop(.5,rgba(255,255,255,0))),-webkit-gradient(linear,left top,left bottom,from(#7189a6),to(#6a83a1))}
-body.stage > article{bottom:40px}
-body.stage > footer{height:40px;background:-webkit-gradient(linear,left top,left bottom,from(rgba(255,255,255,0.3)),color-stop(.5,rgba(255,255,255,0.2)),color-stop(.5,rgba(255,255,255,0))),#000}
-.panel > header{height:40px;line-height:40px;}
-.panel > header h2{margin:0;padding:0;text-align:center;color:#fffeff;text-shadow:0 -1px 0 rgba(0,0,0,0.5);font-weight:normal}
-.panel > header button{position:absolute;left:0;top:0;color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.5);font-size:13px;background:-webkit-gradient(linear,left top,left bottom,from(rgba(255,255,255,0.3)),color-stop(.5,rgba(255,255,255,0.1)),color-stop(.5,rgba(255,255,255,0))),#476b9d;-webkit-box-shadow:inset 0 -1px 1px rgba(0,0,0,0.3),inset 0 1px 1px 0 rgba(0,0,0,0.6),0 1px 0 rgba(255,255,255,0.4);margin:7px;padding:5px 12px;border:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;}
-.panel > header button:active{-webkit-box-shadow:inset 0 -1px 1px rgba(0,0,0,0.3),inset 0 1px 1px 0 rgba(0,0,0,0.6),0 1px 0 rgba(255,255,255,0.4),inset 0 0 20px rgba(255,255,255,0.2)}
-.panel > header button.right{left:auto;right:0}
-.list .item{padding:0 15px;height:50px;line-height:50px;border-bottom:1px solid rgba(0,0,0,0.1);color:#292d39;text-shadow:0 1px 0 #fff;background:#f6f6f7;background:-webkit-gradient(linear,left top,left bottom,from(#fff),color-stop(.5,rgba(255,255,255,0.4)),color-stop(.5,rgba(255,255,255,0))),#f6f6f7;}
-.list .item img{float:right;max-width:30px;max-height:30px;display:inline-block;margin:10px 0}
-.list .item:active{background:#f6f6f7;-moz-box-shadow:inset 0 1px 3px rgba(0,0,0,0.1);-webkit-box-shadow:inset 0 1px 3px rgba(0,0,0,0.1);-moz-box-shadow:inset 0 1px 3px rgba(0,0,0,0.1);-webkit-box-shadow:inset 0 1px 3px rgba(0,0,0,0.1);box-shadow:inset 0 1px 3px rgba(0,0,0,0.1)}
-form{margin:10px;background:#fff;border:1px solid #aeaeae;-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;-moz-box-shadow:0 1px 1px rgba(0,0,0,0.1);-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.1);box-shadow:0 1px 1px rgba(0,0,0,0.1)}
-label{display:block;border-bottom:1px solid #aeaeae;font-size:13px;padding:15px;}
-label:last-child{border-bottom:none}
-label span::after{content:':'}
-select,input{display:block;width:100%;font-size:15px;margin:5px 0 0 0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}
-.contacts.listView > article:empty::after{display:block;text-align:center;margin:10% 0;content:"No contacts"}
-.contacts.showView > article{padding:20px;}
-.contacts.showView > article img{max-width:150px;max-height:150px}
View
1 public/application.js
0 additions, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
View
3 slug.json
@@ -9,8 +9,7 @@
"spine/lib/ajax",
"spine/lib/route",
"spine/lib/manager",
- "spine.mobile",
- "express"
+ "spine.mobile"
],
"libs": []
}
View
59 test/public/specs.js
@@ -1,59 +0,0 @@
-
-
-(function(/*! Stitch !*/) {
- if (!this.specs) {
- var modules = {}, cache = {}, require = function(name, root) {
- var path = expand(root, name), indexPath = expand(path, './index'), module, fn;
- module = cache[path] || cache[indexPath]
- if (module) {
- return module.exports;
- } else if (fn = modules[path] || modules[path = indexPath]) {
- module = {id: path, exports: {}};
- try {
- cache[path] = module;
- fn(module.exports, function(name) {
- return require(name, dirname(path));
- }, module);
- return module.exports;
- } catch (err) {
- delete cache[path];
- throw err;
- }
- } else {
- throw 'module \'' + name + '\' not found';
- }
- }, expand = function(root, name) {
- var results = [], parts, part;
- if (/^\.\.?(\/|$)/.test(name)) {
- parts = [root, name].join('/').split('/');
- } else {
- parts = name.split('/');
- }
- for (var i = 0, length = parts.length; i < length; i++) {
- part = parts[i];
- if (part == '..') {
- results.pop();
- } else if (part != '.' && part != '') {
- results.push(part);
- }
- }
- return results.join('/');
- }, dirname = function(path) {
- return path.split('/').slice(0, -1).join('/');
- };
- this.specs = function(name) {
- return require(name, '');
- }
- this.specs.define = function(bundle) {
- for (var key in bundle)
- modules[key] = bundle[key];
- };
- this.specs.modules = modules;
- this.specs.cache = cache;
- }
- return this.specs.define;
-}).call(this)({
-
-});
-
-require('lib/setup'); for (var key in specs.modules) specs(key);

0 comments on commit 0aa6f82

Please sign in to comment.
Something went wrong with that request. Please try again.