Skip to content

Instantly share code, notes, and snippets.

@bclinkinbeard
Created November 10, 2015 02:50
Show Gist options
  • Save bclinkinbeard/e2cf81e43fbba0ef73ed to your computer and use it in GitHub Desktop.
Save bclinkinbeard/e2cf81e43fbba0ef73ed to your computer and use it in GitHub Desktop.
{
"name": "literasee-editor",
"version": "1.0.0",
"description": "",
"scripts": {
"clean": "rimraf public",
"build:webpack": "webpack --config webpack.config.prod.js",
"build": "npm run clean && npm run build:webpack",
"postinstall": "npm run build",
"start": "nodemon server.js"
},
"engines": {
"node": "4.1.1",
"npm": "3.3.6"
},
"keywords": [],
"author": "Ben Clinkinbeard <ben.clinkinbeard@gmail.com> (http://benclinkinbeard.com/)",
"license": "ISC",
"dependencies": {
"autoprefixer-core": "^5.2.1",
"babel": "^5.8.23",
"babel-loader": "^5.3.2",
"brace": "^0.5.1",
"cookie": "^0.2.2",
"cookie-parser": "^1.4.0",
"css-loader": "^0.17.0",
"express": "^4.13.3",
"file-loader": "^0.8.4",
"history": "^1.8.4",
"isomorphic-fetch": "^2.1.1",
"json-loader": "^0.5.2",
"postcss-loader": "^0.6.0",
"react": "^0.14.0-rc1",
"react-ace": "^2.5.0",
"react-dom": "^0.14.0-rc1",
"react-redux": "^3.0.1",
"react-router": "^1.0.0-rc1",
"redux": "^3.0.2",
"redux-simple-router": "0.0.7",
"redux-thunk": "^1.0.0",
"style-loader": "^0.12.3",
"stylus-loader": "^1.2.1",
"superagent": "^1.4.0",
"url-loader": "^0.5.6",
"webpack": "^1.12.1",
"webpack-dev-middleware": "^1.2.0",
"webpack-hot-middleware": "^2.4.0",
"yeticss": "^7.0.5"
},
"devDependencies": {
"nodemon": "^1.7.1",
"rimraf": "^2.4.3",
"webpack-dev-server": "^1.10.1",
"webpack-hot-middleware": "^2.3.0"
}
}
var path = require('path');
var express = require('express');
var webpack = require('webpack');
var request = require('superagent');
var app = express();
app.use(require('cookie-parser')());
var client_id = process.env.GH_CLIENT_ID || 'foobar';
var client_secret = process.env.GH_CLIENT_SECRET || 'shhh';
var port = process.env.PORT || 3000;
var access_token_url = 'https://github.com/login/oauth/access_token';
var user_url = 'https://api.github.com/user';
//
// LOCAL DEV
//
if (!process.env.GH_CLIENT_ID) {
var config = require('./webpack.config.dev');
var compiler = webpack(config);
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler));
}
//
// OAUTH CALLBACK
//
app.get('*', function (req, res, next) {
// if a URL param named code was sent
// we're on the final step of the OAuth process
// if the param wasn't sent we do nothing
// and pass to the next handler
if (!req.query.code) return next();
// send both tokens and the code to GitHub
request
.post(access_token_url)
.send({
client_id: client_id,
client_secret: client_secret,
code: req.query.code
})
.end(function(err, result){
// now we have the actual token we'll use to make authenticated requests
var token = result.body.access_token;
// we store the token in a cookie for use by the app
// and set it to expire in a month
res.cookie('literasee-oauth-token', token, {
expires: new Date(Date.now() + (1000 * 60 * 60 * 24 * 30))
});
// use the token to get info about the current user
request
.get(user_url)
.set('Authorization', 'token ' + token)
.end(function (err2, result) {
// store the user's GitHub id in a cookie too
res.cookie('literasee-user', result.body.login, {
expires: new Date(Date.now() + (1000 * 60 * 60 * 24 * 30))
});
// finally, send the user to their own URL
res.redirect(result.body.login);
})
});
})
//
// STATIC ASSETS
//
app.use('/public', express.static(__dirname + '/public'));
//
// ROUTE ALL OTHER REQUESTS TO APP
//
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'index.html'));
});
//
// START THE SERVER
//
var server = app.listen(port, function(err) {
if (err) return console.error(err);
console.log('Listening at http://localhost:' + port);
});
var path = require('path');
var webpack = require('webpack');
var yeticss = require('yeticss');
module.exports = {
devtool: 'eval',
entry: [
'webpack-hot-middleware/client',
'./src/app'
],
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js',
publicPath: '/public/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [
{
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
},
{
test: /\.styl$/,
loader: 'style-loader!css-loader!stylus-loader?paths=node_modules/yeticss/lib/yeticss'
}
]
},
stylus: {
use: [yeticss()]
}
};
var path = require('path');
var webpack = require('webpack');
var yeticss = require('yeticss');
module.exports = {
devtool: 'source-map',
entry: [
'./src/app'
],
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js',
publicPath: '/public/'
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
})
],
module: {
loaders: [
{
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
},
{
test: /\.styl$/,
loader: 'style-loader!css-loader!stylus-loader?paths=node_modules/yeticss/lib/yeticss'
}
]
},
stylus: {
use: [yeticss()]
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment