Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added more typings (covers all app.ts imports now). Moved tests=>test…
…. Minor whitespace fixes.
  • Loading branch information
SamuelMarks committed Sep 16, 2015
commit d6e7c6927f9af8499e8f8eb35e3d9ea36dba0ff0
47 changes: 24 additions & 23 deletions imageboard/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/// <reference path='typings/node/node.d.ts' />
/// <reference path='typings/mongodb/mongodb.d.ts' />
/// <reference path='typings/express/express.d.ts' />
/// <reference path='typings/express/express-middleware.d.ts' />

/// <reference path='typings/body-parser/body-parser.d.ts' />
/// <reference path='typings/method-override/method-override.d.ts' />
/// <reference path='typings/errorhandler/errorhandler.d.ts' />

import http = require("http")
import url = require("url")
Expand All @@ -22,7 +23,7 @@ app.set('view engine', 'jade');
app.set('view options', { layout: false });
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(methodOverride(""));
app.use(express.static(__dirname + '/public'));

var env = process.env.NODE_ENV || 'development';
Expand All @@ -40,15 +41,15 @@ app.get('/', routes.index);

app.get('/findImages', function(req, res) {
console.log('getting images from' + req.query['url']);
var req2 = http.get(url.parse(req.query['url']), function(urlres) {
console.log("Got response: " + urlres.statusCode);

http.get(url.parse(req.query['url']), function(urlres) {
console.log("Got response: " + urlres.statusCode);
var text = "";
urlres.on('data', function(chunk: string) {
urlres.on('data', function(chunk: string) {
text += chunk;
});
});
urlres.on('end', function() {
console.log(text);
console.log(text);
var re = /<img[^>]+src=[\"\']([^\'\"]+)[\"\']/g;
var match, matches = [];
while(match = re.exec(text)) {
Expand All @@ -57,26 +58,26 @@ app.get('/findImages', function(req, res) {
res.write(JSON.stringify(matches));
res.end();
});
}).on('error', function(a,e) {
console.log("Got error: " + e.message);
});
}).on('error', function(a,e) {
console.log("Got error: " + e.message);
});
});

app.get('/user/:userid', function(req, res) {
console.log('getting user ' + req.params.userid);
db.getUser(req.params.userid, function(user) {
res.render('user', {
res.render('user', {
title: user._id,
username: user._id,
boards: user.boards
username: user._id,
boards: user.boards
});
});
});

app.get('/user/:userid/newboard', function(req, res) {
res.render('newboard', {
res.render('newboard', {
username: req.params.userid
});
});
});

app.post('/user/:userid/newboard', function(req, res) {
Expand All @@ -93,9 +94,9 @@ app.get('/user/:userid/:boardid', function(req, res) {
})[0];
if(board) {
db.getImages(board.images, function(images) {
res.render('board', {
res.render('board', {
title: user._id,
username: user._id,
username: user._id,
board: board,
images: images
});
Expand All @@ -107,10 +108,10 @@ app.get('/user/:userid/:boardid', function(req, res) {
});

app.get('/user/:userid/:boardid/newpin', function(req, res) {
res.render('newpin', {
res.render('newpin', {
username: req.params.userid,
boardid: req.params.boardid
});
});
});

app.post('/user/:userid/:boardid/newpin', function(req, res) {
Expand All @@ -122,14 +123,14 @@ app.post('/user/:userid/:boardid/newpin', function(req, res) {
app.get('/image/:imageid', function(req, res) {
console.log('getting image ' + req.params.imageid);
db.getImage(req.params.imageid, function(image) {
res.render('image', {
res.render('image', {
title: "image",
image: image
});
});
});

app.listen(3000, function(){
app.listen(process.env.PORT || 3000, function() {
console.log("Demo Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});

Expand Down
3 changes: 2 additions & 1 deletion imageboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.0.1",
"private": true,
"scripts": {
"test": "mocha --compilers ts:typescript-require -u exports -R spec tests/test_*.ts",
"test": "mocha -u exports -R spec test/test_*.js",
"test_ts": "mocha --compilers ts:typescript-require -u exports -R spec test/test_*.ts",
"start": "node app.js"
},
"dependencies": {
Expand Down
23 changes: 22 additions & 1 deletion imageboard/tsd.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,34 @@
"commit": "7a3ca1f0b8a0960af9fc1838f3234cc9d6ce0645"
},
"node/node.d.ts": {
"commit": "7a3ca1f0b8a0960af9fc1838f3234cc9d6ce0645"
"commit": "52b0ea5c9719831eecf6ba7436660e30061a4b3c"
},
"mocha/mocha.d.ts": {
"commit": "7a3ca1f0b8a0960af9fc1838f3234cc9d6ce0645"
},
"chai/chai.d.ts": {
"commit": "7a3ca1f0b8a0960af9fc1838f3234cc9d6ce0645"
},
"mongodb/mongodb.d.ts": {
"commit": "52b0ea5c9719831eecf6ba7436660e30061a4b3c"
},
"serve-static/serve-static.d.ts": {
"commit": "52b0ea5c9719831eecf6ba7436660e30061a4b3c"
},
"mime/mime.d.ts": {
"commit": "52b0ea5c9719831eecf6ba7436660e30061a4b3c"
},
"express/express.d.ts": {
"commit": "52b0ea5c9719831eecf6ba7436660e30061a4b3c"
},
"body-parser/body-parser.d.ts": {
"commit": "52b0ea5c9719831eecf6ba7436660e30061a4b3c"
},
"method-override/method-override.d.ts": {
"commit": "52b0ea5c9719831eecf6ba7436660e30061a4b3c"
},
"errorhandler/errorhandler.d.ts": {
"commit": "52b0ea5c9719831eecf6ba7436660e30061a4b3c"
}
}
}