Skip to content

Commit 0e36d83

Browse files
author
Bowden Kelly
authored
Merge branch 'master' into feat/ts-node
2 parents 41b9d2d + 840936a commit 0e36d83

File tree

8 files changed

+101
-113
lines changed

8 files changed

+101
-113
lines changed

.env.example

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,5 @@ MONGOLAB_URI=mongodb://localhost:27017
33

44
SESSION_SECRET=ashdfjhasdlkjfhalksdjhflak
55

6-
MAILGUN_USER=[email protected]
7-
MAILGUN_PASSWORD=29eldds1uri6
8-
9-
SENDGRID_USER=hslogin
10-
SENDGRID_PASSWORD=hspassword00
11-
126
FACEBOOK_ID=754220301289665
13-
FACEBOOK_SECRET=41860e58c256a3d7ad8267d3c1939a4a
14-
15-
INSTAGRAM_ID=9f5c39ab236a48e0aec354acb77eee9b
16-
INSTAGRAM_SECRET=5920619aafe842128673e793a1c40028
17-
18-
GITHUB_ID=cb448b1d4f0c743a1e36
19-
GITHUB_SECRET=815aa4606f476444691c5f1c16b9c70da6714dc6
20-
21-
TWITTER_KEY=6NNBDyJ2TavL407A3lWxPFKBI
22-
TWITTER_SECRET=ZHaYyK3DQCqv49Z9ofsYdqiUgeoICyh6uoBgFfu7OeYC7wTQKa
23-
24-
GOOGLE_ID=828110519058.apps.googleusercontent.com
25-
GOOGLE_SECRET=JdZsIaWhUFIchmC1a_IZzOHb
26-
27-
TWILIO_SID=AC6f0edc4c47becc6d0a952536fc9a6025
28-
TWILIO_TOKEN=a67170ff7afa2df3f4c7d97cd240d0f3
29-
7+
FACEBOOK_SECRET=41860e58c256a3d7ad8267d3c1939a4a

.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"recommendations": [
33
"eg2.tslint",
4+
"ms-azuretools.vscode-cosmosdb",
45
"streetsidesoftware.code-spell-checker"
56
]
67
}

README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mongod
2323
```
2424
- Build and run the project
2525
```
26+
npm run build
2627
npm start
2728
```
2829
Navigate to `http://localhost:3000`
@@ -73,6 +74,7 @@ The full folder structure of this app is explained below:
7374
| .env.example | API keys, tokens, passwords, database URI. Clone this, but don't check it in to public repos. |
7475
| .travis.yml | Used to configure Travis CI build |
7576
| .copyStaticAssets.ts | Build script that copies images, fonts, and JS libs to the dist folder |
77+
| jest.config.js | Used to configure Jest |
7678
| package.json | File that contains npm dependencies as well as [build scripts](#what-if-a-library-isnt-on-definitelytyped) |
7779
| tsconfig.json | Config settings for compiling server code written in TypeScript |
7880
| tsconfig.tests.json | Config settings for compiling tests written in TypeScript |
@@ -317,24 +319,26 @@ npm install -D jest ts-jest
317319
`jest` is the testing framework itself, and `ts-jest` is just a simple function to make running TypeScript tests a little easier.
318320

319321
### Configure Jest
320-
Jest's configuration lives in `package.json`, so let's open it up and add the following code:
321-
```json
322-
"jest": {
323-
"globals": {
324-
"__TS_CONFIG__": "tsconfig.json"
325-
},
326-
"moduleFileExtensions": [
327-
"ts",
328-
"js"
329-
],
330-
"transform": {
331-
"^.+\\.(ts)$": "./node_modules/ts-jest/preprocessor.js"
332-
},
333-
"testMatch": [
334-
"**/test/**/*.test.(ts|js)"
335-
],
336-
"testEnvironment": "node"
337-
},
322+
Jest's configuration lives in `jest.config.js`, so let's open it up and add the following code:
323+
```js
324+
module.exports = {
325+
globals: {
326+
'ts-jest': {
327+
tsConfigFile: 'tsconfig.json'
328+
}
329+
},
330+
moduleFileExtensions: [
331+
'ts',
332+
'js'
333+
],
334+
transform: {
335+
'^.+\\.(ts|tsx)$': './node_modules/ts-jest/preprocessor.js'
336+
},
337+
testMatch: [
338+
'**/test/**/*.test.(ts|js)'
339+
],
340+
testEnvironment: 'node'
341+
};
338342
```
339343
Basically we are telling Jest that we want it to consume all files that match the pattern `"**/test/**/*.test.(ts|js)"` (all `.test.ts`/`.test.js` files in the `test` folder), but we want to preprocess the `.ts` files first.
340344
This preprocess step is very flexible, but in our case, we just want to compile our TypeScript to JavaScript using our `tsconfig.json`.

jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
globals: {
3+
'ts-jest': {
4+
tsConfigFile: 'tsconfig.json'
5+
}
6+
},
7+
moduleFileExtensions: [
8+
'ts',
9+
'js'
10+
],
11+
transform: {
12+
'^.+\\.(ts|tsx)$': './node_modules/ts-jest/preprocessor.js'
13+
},
14+
testMatch: [
15+
'**/test/**/*.test.(ts|js)'
16+
],
17+
testEnvironment: 'node'
18+
};

package-lock.json

Lines changed: 29 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
"author": "Bowden Kelly",
1010
"license": "MIT",
1111
"scripts": {
12-
"start": "npm run build && npm run watch",
12+
"start": "npm run serve",
1313
"build": "npm run build-sass && npm run build-ts && npm run tslint && npm run copy-static-assets",
14-
"serve": "nodemon dist/server.js",
15-
"watch": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve\"",
14+
"serve": "node dist/server.js",
15+
"watch-node": "nodemon dist/server.js",
16+
"watch": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run watch-node\"",
1617
"test": "jest --forceExit",
1718
"build-ts": "tsc",
1819
"watch-ts": "tsc -w",
@@ -24,27 +25,10 @@
2425
"serve-debug": "nodemon --inspect dist/server.js",
2526
"watch-debug": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve-debug\""
2627
},
27-
"jest": {
28-
"globals": {
29-
"ts-jest": {
30-
"tsConfigFile": "tsconfig.json"
31-
}
32-
},
33-
"moduleFileExtensions": [
34-
"ts",
35-
"js"
36-
],
37-
"transform": {
38-
"^.+\\.(ts|tsx)$": "./node_modules/ts-jest/preprocessor.js"
39-
},
40-
"testMatch": [
41-
"**/test/**/*.test.(ts|js)"
42-
],
43-
"testEnvironment": "node"
44-
},
4528
"dependencies": {
4629
"async": "^2.5.0",
4730
"bcrypt-nodejs": "^0.0.3",
31+
"bluebird": "^3.5.1",
4832
"body-parser": "^1.18.2",
4933
"compression": "^1.7.1",
5034
"connect-mongo": "^1.3.2",
@@ -57,7 +41,7 @@
5741
"fbgraph": "^1.4.1",
5842
"lodash": "^4.17.4",
5943
"lusca": "^1.5.2",
60-
"mongoose": "^4.12.4",
44+
"mongoose": "^4.13.7",
6145
"morgan": "^1.9.0",
6246
"nodemailer": "^2.7.2",
6347
"passport": "^0.4.0",
@@ -69,6 +53,7 @@
6953
"devDependencies": {
7054
"@types/async": "^2.0.40",
7155
"@types/bcrypt-nodejs": "0.0.30",
56+
"@types/bluebird": "^3.5.18",
7257
"@types/body-parser": "^1.16.2",
7358
"@types/compression": "0.0.33",
7459
"@types/connect-mongo": "0.0.34",

src/app.ts

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/**
2-
* Module dependencies.
3-
*/
41
import * as express from "express";
52
import * as compression from "compression"; // compresses requests
63
import * as session from "express-session";
@@ -13,50 +10,38 @@ import * as flash from "express-flash";
1310
import * as path from "path";
1411
import * as mongoose from "mongoose";
1512
import * as passport from "passport";
16-
import expressValidator = require("express-validator");
13+
import * as expressValidator from "express-validator";
14+
import * as bluebird from "bluebird";
1715

1816
const MongoStore = mongo(session);
1917

20-
/**
21-
* Load environment variables from .env file, where API keys and passwords are configured.
22-
*/
18+
// Load environment variables from .env file, where API keys and passwords are configured
2319
dotenv.config({ path: ".env.example" });
2420

25-
26-
/**
27-
* Controllers (route handlers).
28-
*/
21+
// Controllers (route handlers)
2922
import * as homeController from "./controllers/home";
3023
import * as userController from "./controllers/user";
3124
import * as apiController from "./controllers/api";
3225
import * as contactController from "./controllers/contact";
3326

34-
/**
35-
* API keys and Passport configuration.
36-
*/
27+
28+
// API keys and Passport configuration
3729
import * as passportConfig from "./config/passport";
3830

39-
/**
40-
* Create Express server.
41-
*/
31+
// Create Express server
4232
const app = express();
4333

44-
/**
45-
* Connect to MongoDB.
46-
*/
47-
// mongoose.Promise = global.Promise;
48-
mongoose.connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI);
49-
50-
mongoose.connection.on("error", () => {
51-
console.log("MongoDB connection error. Please make sure MongoDB is running.");
52-
process.exit();
34+
// Connect to MongoDB
35+
const mongoUrl = process.env.MONGOLAB_URI;
36+
(<any>mongoose).Promise = bluebird;
37+
mongoose.connect(mongoUrl, {useMongoClient: true}).then(
38+
() => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ },
39+
).catch(err => {
40+
console.log("MongoDB connection error. Please make sure MongoDB is running. " + err);
41+
// process.exit();
5342
});
5443

55-
56-
57-
/**
58-
* Express configuration.
59-
*/
44+
// Express configuration
6045
app.set("port", process.env.PORT || 3000);
6146
app.set("views", path.join(__dirname, "../views"));
6247
app.set("view engine", "pug");
@@ -70,7 +55,7 @@ app.use(session({
7055
saveUninitialized: true,
7156
secret: process.env.SESSION_SECRET,
7257
store: new MongoStore({
73-
url: process.env.MONGODB_URI || process.env.MONGOLAB_URI,
58+
url: mongoUrl,
7459
autoReconnect: true
7560
})
7661
}));
@@ -86,13 +71,13 @@ app.use((req, res, next) => {
8671
app.use((req, res, next) => {
8772
// After successful login, redirect back to the intended page
8873
if (!req.user &&
89-
req.path !== "/login" &&
90-
req.path !== "/signup" &&
91-
!req.path.match(/^\/auth/) &&
92-
!req.path.match(/\./)) {
74+
req.path !== "/login" &&
75+
req.path !== "/signup" &&
76+
!req.path.match(/^\/auth/) &&
77+
!req.path.match(/\./)) {
9378
req.session.returnTo = req.path;
9479
} else if (req.user &&
95-
req.path == "/account") {
80+
req.path == "/account") {
9681
req.session.returnTo = req.path;
9782
}
9883
next();

views/partials/footer.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
footer
22
.container.text-center
3-
p.pull-left © 2016 Company, Inc. All Rights Reserved
3+
p.pull-left © 2018 Company, Inc. All Rights Reserved
44
iframe.pull-right(src="https://ghbtns.com/github-btn.html?user=Microsoft&repo=TypeScript-Node-Starter&type=star&count=true" frameborder="0" scrolling="0" width="90px" height="20px" style="margin-top:15px")
55

0 commit comments

Comments
 (0)