From d5da63ece20a140389ac1f1811b5551c7f989cfa Mon Sep 17 00:00:00 2001 From: David Erwin Date: Mon, 31 Oct 2016 12:17:24 -0400 Subject: [PATCH] Initial commit --- .babelrc | 12 ++++ .editorconfig | 15 +++++ .eslintignore | 1 + .eslintrc | 3 + .gitignore | 8 +++ .travis-yml | 3 + LICENSE | 11 ++++ package.json | 122 ++++++++++++++++++++++++++++++++++++++ server/api/routes.js | 16 +++++ server/comments/routes.js | 32 ++++++++++ server/index.js | 46 ++++++++++++++ webpack.config.babel.js | 79 ++++++++++++++++++++++++ 12 files changed, 348 insertions(+) create mode 100644 .babelrc create mode 100644 .editorconfig create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 .travis-yml create mode 100644 LICENSE create mode 100644 package.json create mode 100644 server/api/routes.js create mode 100644 server/comments/routes.js create mode 100644 server/index.js create mode 100644 webpack.config.babel.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 000000000..f8b877ec3 --- /dev/null +++ b/.babelrc @@ -0,0 +1,12 @@ +{ + "sourceMaps": true, + "presets": [ + "stage-0", + "es2015-minimal" + ], + "plugins": [ + ["transform-decorators-legacy"], + ["transform-react-jsx", { "pragma": "h" }], + ["transform-object-assign"] + ] +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..9c378bd19 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[{package.json,.*rc,*.yml}] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..fd5305a97 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +test/*.conf.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000..559f28431 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": ["standard", "standard-jsx"] +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..2209ac81a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/node_modules +/npm-debug.log +/build +/server/widgets/*.js +/server/widgets/*.html +.DS_Store +config.json +*.iml diff --git a/.travis-yml b/.travis-yml new file mode 100644 index 000000000..85242354a --- /dev/null +++ b/.travis-yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - 4 diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..41cbbd5aa --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +Copyright 2016 Mozilla Foundation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + +See the License for the specific language governing permissions and limitations under the License. diff --git a/package.json b/package.json new file mode 100644 index 000000000..2caacf24f --- /dev/null +++ b/package.json @@ -0,0 +1,122 @@ +{ + "name": "coral-talk", + "version": "0.0.1", + "description": "A commenting platform.", + + "author": "The Coral Project", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/jde/talk/issues" + }, + "homepage": "https://github.com/jde/talk#readme", + + "main": "src/server.js", + + "repository": { + "type": "git", + "url": "git+https://github.com/jde/talk.git" + }, + + "scripts": { + "dev": "webpack-dev-server --inline --hot --progress", + "prestart": "npm run build", + "build": "webpack -p --progress", + "test": "npm run -s lint && npm run -s test:karma", + "test:karma": "karma start test/karma.conf.js --single-run", + "lint": "eslint {src,test}", + "server": "cd server; node index.js", + "start": "cd server; node index.js" + }, + + "keywords": [ + "coral", + "ask", + "webpack", + "rollup", + "babel", + "preact" + ], + + "devDependencies": { + "autoprefixer": "^6.3.3", + "babel": "^6.5.2", + "babel-core": "^6.7.2", + "babel-eslint": "^6.0.0", + "babel-loader": "^6.2.4", + "babel-plugin-transform-decorators-legacy": "^1.3.4", + "babel-plugin-transform-react-jsx": "^6.6.5", + "babel-preset-es2015": "^6.6.0", + "babel-preset-es2015-minimal": "^2.0.0", + "babel-preset-es2015-rollup": "^1.1.1", + "babel-preset-stage-0": "^6.5.0", + "babel-register": "^6.7.2", + "babel-runtime": "^6.6.1", + "chai": "^3.5.0", + "core-js": "^2.2.1", + "css-loader": "^0.23.1", + "eslint": "^2.5.3", + "extract-text-webpack-plugin": "^1.0.1", + "file-loader": "^0.8.5", + "html-webpack-plugin": "^2.14.0", + "json-loader": "^0.5.4", + "karma": "^0.13.22", + "karma-chai": "^0.1.0", + "karma-chai-sinon": "^0.1.5", + "karma-mocha": "^0.2.2", + "karma-mocha-reporter": "^2.0.0", + "karma-phantomjs-launcher": "^1.0.0", + "karma-sourcemap-loader": "^0.3.7", + "karma-webpack": "^1.7.0", + "less": "^2.6.1", + "less-loader": "^2.2.2", + "mocha": "^2.4.5", + "ncp": "^2.0.0", + "phantomjs-prebuilt": "^2.1.6", + "postcss-loader": "^0.8.2", + "raw-loader": "^0.5.1", + "rollup-plugin-babel": "2.4.0", + "rollup-plugin-commonjs": "^2.2.1", + "rollup-plugin-memory": "^1.0.0", + "rollup-plugin-node-resolve": "^1.5.0", + "rollup-plugin-replace": "^1.1.0", + "rollup-plugin-uglify": "^0.3.1", + "sinon": "^1.17.3", + "sinon-chai": "^2.8.0", + "source-map-loader": "^0.1.5", + "style-loader": "^0.13.0", + "superstatic": "^4.0.2", + "uglify-js": "^2.6.2", + "url-loader": "^0.5.7", + "webpack": "^1.12.14", + "webpack-dev-server": "^1.14.1" + }, + "dependencies": { + "aws-sdk": "^2.3.16", + "babel-helpers": "^6.8.0", + "babel-plugin-transform-object-assign": "^6.5.0", + "body-parser": "^1.15.0", + "compression": "^1.6.1", + "cors": "^2.7.1", + "decko": "^1.1.3", + "express": "^4.13.4", + "flatpickr": "^1.8.8", + "marked": "^0.3.6", + "preact": "^5.4.0", + "preact-compat": "^1.6.1", + "preact-router": "^1.3.0", + "preact-svg": "^1.6.0", + "proptypes": "^0.14.3", + "pug": "^2.0.0-beta2", + "react-gmaps": "^1.5.0", + "request": "^2.75.0", + "request-promise": "^4.1.1", + "rollup": "^0.25.8", + "rollup-plugin-postcss": "0.0.27", + "standard": "^7.1.2", + "wildemitter": "^1.2.0" + }, + "main": "webpack.config.babel.js", + "directories": { + "test": "test" + } +} diff --git a/server/api/routes.js b/server/api/routes.js new file mode 100644 index 000000000..2eb06fe1c --- /dev/null +++ b/server/api/routes.js @@ -0,0 +1,16 @@ +/* API routes contains general api funcitonality. */ + +var express = require('express'); +var router = express.Router(); + +router.use(function auth(req, res, next) { + console.log('Read the user cookie here.'); + next(); +}); + +// Base route provides server version information. +router.get('/', function(req, res) { + res.send('App version information goes here....'); +}); + +module.exports = router; \ No newline at end of file diff --git a/server/comments/routes.js b/server/comments/routes.js new file mode 100644 index 000000000..e7f389865 --- /dev/null +++ b/server/comments/routes.js @@ -0,0 +1,32 @@ +/* Api comment routes define the handlers for incoming comment related requests. */ + +var express = require('express'); +var router = express.Router(); + +router.use(function (req, res, next) { + console.log("Read the cookie to make sure users can do this thing with comments.") + next(); +}); + + +router.get('/', function(req, res) { + res.send('Read all of the comments ever'); +}); + +router.get('/:commentId', function(req, res) { + res.send('Read a comment'); +}); + +router.post('/', function(req, res) { + res.send('Write a comment'); +}); + +router.put('/:commentId', function(req, res) { + res.send('Update a comment'); +}); + +router.delete('/:commentId', function(req, res) { + res.send('Delete a comment'); +}); + +module.exports = router; \ No newline at end of file diff --git a/server/index.js b/server/index.js new file mode 100644 index 000000000..02b184ed0 --- /dev/null +++ b/server/index.js @@ -0,0 +1,46 @@ +/* This is the entrypoint for the Talk Platform server. */ + +// Initialize application framework. +var express = require('express'); +var app = express(); + +// Load routes. +var apiRoutes = require("./api/routes"); +var commentRoutes = require('./comments/routes'); + +// Initialize mongoose. +var mongoose = require("mongoose"); + +// Connect to the database +mongoose.connect('mongodb://localhost/talk'); +var db = mongoose.connection; +db.on('error', console.error.bind(console, 'connection error:')); +db.once('open', function() { + ready(); +}); + +// Initialize Static Endpoints. +var initializeStatic = function() { + // TODO +} + +// Initialize API endpoints. +var initializeAPI = function () { + app.use('/api/v1', apiRoutes); + app.use('/api/v1/comments', commentRoutes); +} + +// Initialize server when ready. +var ready = function () { + + var port = 1618; + + initializeStaticEndpoints(); + initializeAPI(); + + // Listen for incoming requests. + app.listen(port, function () { + console.log('Listening on port ' + port + '!'); + }); + +} \ No newline at end of file diff --git a/webpack.config.babel.js b/webpack.config.babel.js new file mode 100644 index 000000000..fb2b4b05d --- /dev/null +++ b/webpack.config.babel.js @@ -0,0 +1,79 @@ +import webpack from 'webpack'; +import ExtractTextPlugin from 'extract-text-webpack-plugin'; +import HtmlWebpackPlugin from 'html-webpack-plugin'; +import autoprefixer from 'autoprefixer'; + +var path = require('path'); + +const ENV = process.env.NODE_ENV || 'development'; + +const CSS_MAPS = ENV!=='production'; + +module.exports = { + context: path.resolve(__dirname, '/src'), + entry: ['./server'], + + output: { + path: `${__dirname}/build`, + publicPath: '/', + filename: 'bundle.js', + library: 'Ask' + }, + + externals: {}, + + module: { + preLoaders: [ + { + test: /\.jsx?$/, + exclude: /src\//, + loader: 'source-map' + } + ], + loaders: [ + { + test: /\.jsx?$/, + exclude: /node_modules/, + loader: 'babel' + }, + { + test: /\.css$/, + loader: 'style-loader!css-loader' + }, + { + test: /\.json$/, + loader: 'json' + }, + { + test: /\.(xml|html|txt|md)$/, + loader: 'raw' + }, + { + test: /\.(svg|woff2?|ttf|eot|jpe?g|png|gif)(\?.*)?$/i, + loader: ENV==='production' ? 'file?name=[path][name]_[hash:base64:5].[ext]' : 'url' + } + ] + }, + + plugins: ([ + new webpack.NoErrorsPlugin(), + new webpack.DefinePlugin({ + 'process.env': JSON.stringify({ NODE_ENV: ENV }) + }) + ]).concat(ENV==='production' ? [ + new webpack.optimize.OccurenceOrderPlugin() + ] : []), + + stats: { colors: true }, + + node: { + global: true, + process: false, + Buffer: false, + __filename: false, + __dirname: false, + setImmediate: false + }, + + devtool: ENV==='production' ? 'source-map' : 'cheap-module-eval-source-map' +};