Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit bf763da

Browse files
Modernize dependencies for the ImageBoard sample. Use DefinitelyTyped definitions.
1 parent fdc9554 commit bf763da

File tree

12 files changed

+2955
-193
lines changed

12 files changed

+2955
-193
lines changed

imageboard/ImageBoard.csproj

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />
4+
<PropertyGroup>
5+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion>
6+
<TypeScriptToolsVersion>1.4</TypeScriptToolsVersion>
7+
</PropertyGroup>
38
<PropertyGroup>
49
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
510
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -18,6 +23,8 @@
1823
<DefineConstants>DEBUG;TRACE</DefineConstants>
1924
<ErrorReport>prompt</ErrorReport>
2025
<WarningLevel>4</WarningLevel>
26+
<TypeScriptRemoveComments>false</TypeScriptRemoveComments>
27+
<TypeScriptSourceMap>true</TypeScriptSourceMap>
2128
</PropertyGroup>
2229
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2330
<DebugType>pdbonly</DebugType>
@@ -26,6 +33,8 @@
2633
<DefineConstants>TRACE</DefineConstants>
2734
<ErrorReport>prompt</ErrorReport>
2835
<WarningLevel>4</WarningLevel>
36+
<TypeScriptRemoveComments>false</TypeScriptRemoveComments>
37+
<TypeScriptSourceMap>true</TypeScriptSourceMap>
2938
</PropertyGroup>
3039
<PropertyGroup>
3140
<RootNamespace>ImageBoard</RootNamespace>
@@ -40,15 +49,16 @@
4049
<Reference Include="System.Xml.Linq" />
4150
</ItemGroup>
4251
<ItemGroup>
43-
<None Include="app.ts" />
44-
<None Include="db.ts" />
45-
<None Include="mongodb.ts" />
52+
<TypeScriptCompile Include="app.ts" />
53+
<TypeScriptCompile Include="db.ts" />
4654
<None Include="package.json" />
47-
<None Include="routes\index.ts" />
55+
<TypeScriptCompile Include="routes\index.ts" />
4856
<None Include="views\board.jade" />
4957
<None Include="views\image.jade" />
5058
<None Include="views\index.jade" />
5159
<None Include="views\layout.jade" />
60+
<None Include="views\newboard.jade" />
61+
<None Include="views\newpin.jade" />
5262
<None Include="views\user.jade" />
5363
</ItemGroup>
5464
<ItemGroup>
@@ -58,8 +68,18 @@
5868
<Folder Include="public\images\" />
5969
<Folder Include="public\javascripts\" />
6070
</ItemGroup>
71+
<ItemGroup>
72+
<TypeScriptCompile Include="typings\express\express-middleware.d.ts" />
73+
<TypeScriptCompile Include="typings\express\express.d.ts" />
74+
<TypeScriptCompile Include="typings\mongodb\mongodb.d.ts" />
75+
<TypeScriptCompile Include="typings\node\node.d.ts" />
76+
</ItemGroup>
6177
<Import Project="$(MSBuildToolsPath)\Microsoft.CSHARP.Targets" />
6278
<ProjectExtensions>
6379
<VisualStudio AllowExistingFolder="true" />
6480
</ProjectExtensions>
81+
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
82+
<TypeScriptModuleKind>commonjs</TypeScriptModuleKind>
83+
</PropertyGroup>
84+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
6585
</Project>

imageboard/app.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
1-
///<reference path='../node/node.d.ts' />
1+
/// <reference path='typings/node/node.d.ts' />
2+
/// <reference path='typings/mongodb/mongodb.d.ts' />
3+
/// <reference path='typings/express/express.d.ts' />
4+
/// <reference path='typings/express/express-middleware.d.ts' />
5+
26

37
import http = require("http")
48
import url = require("url")
59
import routes = require("./routes/index")
610
import db = require("./db")
711
import express = require("express")
12+
import bodyParser = require("body-parser");
13+
import methodOverride = require("method-override");
14+
import errorHandler = require("errorhandler");
815

916
var app = express();
1017

1118
// Configuration
12-
app.configure(function(){
13-
app.set('views', __dirname + '/views');
14-
app.set('view engine', 'jade');
15-
app.set('view options', { layout: false });
16-
app.use(express.bodyParser());
17-
app.use(express.methodOverride());
18-
app.use(express.static(__dirname + '/public'));
19-
});
2019

21-
app.configure('development', function(){
22-
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
23-
});
20+
app.set('views', __dirname + '/views');
21+
app.set('view engine', 'jade');
22+
app.set('view options', { layout: false });
23+
app.use(bodyParser.urlencoded({ extended: true }));
24+
app.use(bodyParser.json());
25+
app.use(methodOverride());
26+
app.use(express.static(__dirname + '/public'));
2427

25-
app.configure('production', function(){
26-
app.use(express.errorHandler());
27-
});
28+
var env = process.env.NODE_ENV || 'development';
29+
if (env === 'development') {
30+
app.use(errorHandler({ dumpExceptions: true, showStack: true }));
31+
}
32+
else if (env === 'production') {
33+
app.use(errorHandler());
34+
}
2835

2936

3037
// Routes
@@ -94,7 +101,7 @@ app.get('/user/:userid/:boardid', function(req, res) {
94101
});
95102
});
96103
} else {
97-
res.send('not found', 404);
104+
res.send(404, 'not found');
98105
}
99106
});
100107
});

imageboard/db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Mongo
22
import mongodb = require('mongodb');
33

4-
var server = new mongodb.Server('localhost', 27017, {auto_reconnect: true}, {})
5-
var db = new mongodb.Db('mydb', server);
4+
var server = new mongodb.Server('localhost', 27017, {auto_reconnect: true})
5+
var db = new mongodb.Db('mydb', server, { w: 1 });
66
db.open(function() {});
77

88
export interface User {

imageboard/express.d.ts

Lines changed: 0 additions & 128 deletions
This file was deleted.

imageboard/mongodb.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

imageboard/package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
2-
"name": "application-name"
3-
, "version": "0.0.1"
4-
, "private": true
5-
, "dependencies": {
6-
"express": ">= 3.0.0"
7-
, "ejs": ">= 0.5.0"
8-
, "jade": ">= 0.0.1"
9-
, "mongodb": ">= 1.0.0"
2+
"name": "imageboard-sample",
3+
"version": "0.0.1",
4+
"private": true,
5+
"dependencies": {
6+
"express": "4.11.1",
7+
"body-parser": "1.10.2",
8+
"errorhandler": "1.3.2",
9+
"method-override": "2.3.1",
10+
"ejs": ">= 0.5.0",
11+
"jade": ">= 0.0.1",
12+
"mongodb": ">= 1.4.29"
1013
}
1114
}

imageboard/routes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import express = require("express")
22
import db = require("../db")
33

4-
export function index(req: express.ExpressServerRequest, res: express.ExpressServerResponse){
4+
export function index(req: express.Request, res: express.Response) {
55
db.getUsers(function(users) {
66
console.dir(users);
77
res.render('index', { title: 'ImageBoard', users: users })
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path="express.d.ts" />
2+
3+
declare module "body-parser" {
4+
import express = require("express");
5+
function bodyParser(): express.RequestHandler;
6+
module bodyParser {
7+
function urlencoded(opts?: any): express.RequestHandler;
8+
function json(): express.RequestHandler;
9+
}
10+
export = bodyParser;
11+
}
12+
13+
declare module "method-override" {
14+
import express = require("express");
15+
function methodOverride(): express.RequestHandler;
16+
export = methodOverride;
17+
}
18+
19+
declare module "errorhandler" {
20+
import express = require("express");
21+
function errorHandler(opts?: any): express.ErrorRequestHandler;
22+
export = errorHandler;
23+
}

0 commit comments

Comments
 (0)