Permalink
Browse files

Back to serveup solution and solved CORS

Signed-off-by: Wenwei Cai <stanley.w.cai@gmail.com>
  • Loading branch information...
swcai committed Mar 8, 2013
1 parent 1c0caf8 commit 0aa6f82f55edc2f0bf7d7b070f73949466de2bde
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
@@ -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
@@ -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
@@ -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

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -9,8 +9,7 @@
"spine/lib/ajax",
"spine/lib/route",
"spine/lib/manager",
- "spine.mobile",
- "express"
+ "spine.mobile"
],
"libs": []
}
View
@@ -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.