diff --git a/app.js b/app.js index 4dca616..667482a 100644 --- a/app.js +++ b/app.js @@ -4,7 +4,7 @@ import route from 'koa-route'; import logger from 'koa-logger'; import favicon from 'koa-favicon'; import compress from 'koa-compress'; -import staticHandler from 'koa-static'; +import staticHandler from 'koa-file-server'; import bodyparser from 'koa-bodyparser'; import React from 'react'; import co from 'co'; @@ -13,7 +13,7 @@ import index from './routes/index'; import search from './routes/search'; import share from './routes/share'; import itunesProxy from './routes/itunes-proxy'; -import {routes} from './views/app.jsx'; +import {routes} from './views/app'; import zlib from 'zlib'; import createHandler from './lib/react-handler'; @@ -46,7 +46,7 @@ app.use(bodyparser()); app.use(compress({flush: zlib.Z_SYNC_FLUSH })); app.use(favicon(path.join(__dirname, '/public/images/favicon.png'))); app.use(logger()); -app.use(staticHandler(path.join(__dirname, 'public'))); +app.use(staticHandler({root: 'public', maxage: 31536000000})); let mongo = {}; @@ -96,7 +96,17 @@ app.use(route.get('*', function* () { module.exports = app; if (!module.parent) { - app.listen(process.env.PORT || 3000, function() { - debug('Koa server listening on port ' + (process.env.PORT || 3000)); - }); + if (process.env.LOCALHOST_KEY) { + require('spdy').createServer({ + key: process.env.LOCALHOST_KEY, + cert: process.env.LOCALHOST_CRT + }, app.callback()).listen(3000, function() { + debug('Koa SPDY server listening on port ' + (process.env.PORT || 3000)); + }); + } else { + app.listen(process.env.PORT || 3000, function() { + debug('Koa HTTP server listening on port ' + (process.env.PORT || 3000)); + }); + } + } diff --git a/lib/react-handler.js b/lib/react-handler.js index 98a04b6..dda415a 100644 --- a/lib/react-handler.js +++ b/lib/react-handler.js @@ -1,4 +1,4 @@ -var Router = require('react-router'); +import Router from 'react-router'; export default function* (routes, url) { let router = Router.create({ diff --git a/package.json b/package.json index 719a6d7..bb1aa32 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,7 @@ "build": "babel -d public/views views", "watch": "parallelshell \"npm run watch-js\" \"npm run watch-server\"", "watch-server": "nodemon -x \"node -r 'babel/register'\" -e js,jsx -i public/ app.js", - "watch-js": "babel -wd public/views views", - "clean": "rm -f ./public/scripts/bundle.js", + "watch-js": "babel --modules system -wd public/views views", "postinstall": "jspm install" }, "engines": { @@ -32,14 +31,14 @@ "browserify": "^10.1.3", "co": "^4.5.4", "debug": "^2.1.1", - "jspm": "^0.15.7", + "jspm": "^0.16.0-beta", "koa": "^0.21.0", "koa-bodyparser": "^2.0.0", "koa-compress": "^1.0.8", "koa-favicon": "^1.2.0", + "koa-file-server": "^2.3.1", "koa-logger": "^1.2.2", "koa-route": "^2.4.0", - "koa-static": "^1.4.9", "moment": "^2.10.3", "mongodb-promisified": "^1.0.2", "node-uuid": "^1.4.2", @@ -51,8 +50,7 @@ "reactify": "^1.1.1", "spotify": "^0.3.0", "superagent": "^1.2.0", - "superagent-bluebird-promise": "^2.0.2", - "uglifyjs": "^2.4.10" + "superagent-bluebird-promise": "^2.0.2" }, "devDependencies": { "co-mocha": "^1.1.0", @@ -61,19 +59,19 @@ "mocha": "^2.1.0", "nodemon": "^1.3.7", "parallelshell": "^1.1.1", - "should": "^6.0.3" + "should": "^6.0.3", + "spdy": "^1.32.0" }, "jspm": { "directories": { "baseURL": "public" }, "dependencies": { - "babel-core": "npm:babel-core@^5.5.8", "jsx": "github:floatdrop/plugin-jsx@^1.1.0", "react": "npm:react@0.13.3", "react-google-analytics": "npm:react-google-analytics@0.2.0", "react-router": "npm:react-router@0.13.3", - "superagent": "npm:superagent@^1.2.0" + "superagent": "npm:superagent@1.2.0" }, "devDependencies": { "babel": "npm:babel-core@^5.1.13", diff --git a/public/config.js b/public/config.js index c1b734f..89e9cfa 100644 --- a/public/config.js +++ b/public/config.js @@ -1,5 +1,6 @@ System.config({ "baseURL": "/", + "defaultJSExtensions": true, "transpiler": "babel", "babelOptions": { "optional": [ @@ -7,15 +8,15 @@ System.config({ ] }, "paths": { - "*": "*.js", - "*.jsx": "*.js", - "github:*": "jspm_packages/github/*.js", - "npm:*": "jspm_packages/npm/*.js" + "github:*": "jspm_packages/github/*", + "npm:*": "jspm_packages/npm/*" } }); System.config({ "map": { + "babel": "npm:babel-core@5.5.8", + "babel-runtime": "npm:babel-runtime@5.5.8", "core-js": "npm:core-js@0.9.17", "jsx": "github:floatdrop/plugin-jsx@1.1.0", "react": "npm:react@0.13.3", diff --git a/routes/index.js b/routes/index.js index 0a5b961..75df717 100644 --- a/routes/index.js +++ b/routes/index.js @@ -2,7 +2,7 @@ import React from 'react'; import createHandler from '../lib/react-handler'; -import {routes} from '../views/app.jsx'; +import {routes} from '../views/app'; module.exports = function* () { let recents = []; diff --git a/routes/share.js b/routes/share.js index 5806b71..8432779 100644 --- a/routes/share.js +++ b/routes/share.js @@ -1,6 +1,6 @@ import React from 'react'; import createHandler from '../lib/react-handler'; -import {routes} from '../views/app.jsx'; +import {routes} from '../views/app'; import services from '../lib/services'; let formatAndSort = function(matches, serviceId) { diff --git a/views/app.jsx b/views/app.js similarity index 53% rename from views/app.jsx rename to views/app.js index 8b99986..3a1c28c 100644 --- a/views/app.jsx +++ b/views/app.js @@ -1,18 +1,12 @@ -'use strict'; +import React from 'react'; +import Router, {Route, DefaultRoute, NotFoundRoute, RouteHandler} from 'react-router'; +import ga, {Initializer as GAInitiailizer} from 'react-google-analytics'; +import Home from './home'; +import Share from './share'; +import Head from './head'; +import ErrorView from './error'; -var React = require('react'); -var Router = require('react-router'); -var Route = require('react-router').Route; -var DefaultRoute = require('react-router').DefaultRoute; -var NotFoundRoute = require('react-router').NotFoundRoute; -var RouteHandler = require('react-router').RouteHandler; -var Home = require('./home.jsx'); -var Share = require('./share.jsx'); -var Head = require('./head.jsx'); -var ga = require('react-google-analytics'); -var GAInitiailizer = ga.Initializer; - -var App = React.createClass({ +let App = React.createClass({ render: function () { return ( @@ -20,25 +14,26 @@ var App = React.createClass({
{this.props.error.stack || ''}+
{this.props.error.stack || ""}-