Skip to content

Commit

Permalink
update server stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoitch committed Jan 22, 2015
1 parent 874115f commit 3a01391
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
## Prerequisites
* [node.js](http://nodejs.org/) ([install package](http://nodejs.org/download/)) or `brew install node`

## Configuration (optional)
## Server Configuration (optional)
For embeds and image uploads, you will have to configure the built-in server:
Rename `server/config.example.json` to `server/config.json` and enter your AWS credentials in the file.
Rename `server/config.example.json` to `server/config.json` and enter your AWS/Embedly credentials in the file.

## Playing
1. Install dependencies: `npm install`
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"author": "Garth Poitras <garth22@gmail.com> (http://garthpoitras.com/)",
"license": "MIT",
"dependencies": {
"aws-sdk": "^2.0.17",
"busboy": "^0.2.8",
"aws-sdk": "^2.1.7",
"busboy": "^0.2.9",
"embedly": "^1.0.2",
"express": "^4.9.0"
"express": "^4.11.1"
},
"devDependencies": {
"gulp": "^3.8.10",
Expand Down
10 changes: 3 additions & 7 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
var express = require('express');
var config = require('./config');
var S3UploadService = require('./services/s3-uploader');
var UploadService = require('./services/upload');
var EmbedService = require('./services/embed');

// Express app
var app = express();

// Demo setup
app.use(express.static('demo'));
app.use('/dist', express.static('dist'));
app.get('/', function(req, res) {
res.sendFile('/');
});

// Routes
app.post('/upload', S3UploadService);
app.post('/upload', UploadService);
app.get('/embed', EmbedService);

app.listen(5000, function() {
console.log('content-kit-editor server: listening on port %d', this.address().port);
console.log('content-kit-server: listening on port %d', this.address().port);
});

module.exports = app;
9 changes: 5 additions & 4 deletions server/services/embed.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
var embedly = require('embedly');
var util = require('util');
var config = require('../config');

module.exports = function(req, res) {

var url = req.query.url;
if (!(/^https?:\/\//i).test(url)) {
url = 'http://' + url;
}

new embedly({key: config.embedlyKey}, function(err, api) {
if (err) {
console.log(err);
return res.status(500).json(err);
}

Expand All @@ -17,12 +20,10 @@ module.exports = function(req, res) {

api.oembed({url: url}, function(err, objs) {
if (err) {
console.log(err, objs);
var message = JSON.parse(objs).error_message;
return res.status(500).json(message);
}

console.log(util.inspect(objs[0]));
res.json(objs[0]);
});

Expand Down
File renamed without changes.

0 comments on commit 3a01391

Please sign in to comment.