1
0
mirror of https://github.com/microsoft/TypeScript-Node-Starter.git synced 2025-11-08 16:17:37 +00:00

Merge branch 'master' into refactor-remove-unused-imports

This commit is contained in:
Orta
2019-06-19 14:26:30 -07:00
committed by GitHub
12 changed files with 4628 additions and 4574 deletions

2
.gitignore vendored
View File

@@ -37,3 +37,5 @@ Thumbs.db
# Ignore built ts files
dist/**/*
# ignore yarn.lock
yarn.lock

View File

@@ -1,7 +1,6 @@
{
"recommendations": [
"eg2.tslint",
"ms-vscode.vscode-typescript-tslint-plugin",
"ms-azuretools.vscode-cosmosdb",
"streetsidesoftware.code-spell-checker"
]
}

View File

@@ -10,9 +10,8 @@
"tslint.ignoreDefinitionFiles": false,
"tslint.autoFixOnSave": true,
"tslint.exclude": "**/node_modules/**/*",
"cSpell.words": [
"csrf",
"definitelytyped",
"promisified"
]
"appService.zipIgnorePattern": [
".vscode{,/**}"
],
"appService.deploySubpath": ""
}

View File

@@ -176,7 +176,7 @@ The full folder structure of this app is explained below:
| **src/public** | Static assets that will be used client side |
| **src/types** | Holds .d.ts files not found on DefinitelyTyped. Covered more in this [section](#type-definition-dts-files) |
| **src**/server.ts | Entry point to your express app |
| **test** | Contains your tests. Seperate from source because there is a different build process. |
| **test** | Contains your tests. Separate from source because there is a different build process. |
| **views** | Views define how your app renders on the client. In this case we're using pug |
| .env.example | API keys, tokens, passwords, database URI. Clone this, but don't check it in to public repos. |
| .travis.yml | Used to configure Travis CI build |

View File

@@ -1,7 +1,7 @@
module.exports = {
globals: {
'ts-jest': {
tsConfigFile: 'tsconfig.json'
tsConfig: 'tsconfig.json'
}
},
moduleFileExtensions: [
@@ -9,10 +9,10 @@ module.exports = {
'js'
],
transform: {
'^.+\\.(ts|tsx)$': './node_modules/ts-jest/preprocessor.js'
'^.+\\.(ts|tsx)$': 'ts-jest'
},
testMatch: [
'**/test/**/*.test.(ts|js)'
],
testEnvironment: 'node'
};
};

9135
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -42,13 +42,13 @@
"fbgraph": "^1.4.1",
"lodash": "^4.17.5",
"lusca": "^1.5.2",
"mongoose": "^4.13.11",
"mongoose": "^5.4.2",
"nodemailer": "^4.4.1",
"passport": "^0.4.0",
"passport-facebook": "^2.1.1",
"passport-local": "^1.0.0",
"pug": "^2.0.0-rc.4",
"request": "^2.83.0",
"pug": "^2.0.3",
"request": "^2.88.0",
"request-promise": "^4.2.2",
"winston": "^2.4.0"
},
@@ -64,7 +64,7 @@
"@types/express": "^4.11.1",
"@types/express-session": "^1.15.8",
"@types/jest": "^22.1.3",
"@types/jquery": "^3.2.17",
"@types/jquery": "^3.3.29",
"@types/lodash": "^4.14.91",
"@types/lusca": "^1.5.0",
"@types/mongodb": "^3.0.5",
@@ -81,14 +81,14 @@
"@types/winston": "^2.3.7",
"chai": "^4.1.2",
"concurrently": "^3.5.1",
"jest": "^22.0.4",
"node-sass": "^4.7.2",
"nodemon": "^1.13.0",
"jest": "^24.0.0",
"node-sass": "^4.12.0",
"nodemon": "^1.18.10",
"shelljs": "^0.8.1",
"supertest": "^3.0.0",
"ts-jest": "^22.0.4",
"ts-jest": "^24.0.0",
"ts-node": "^5.0.0",
"tslint": "^5.9.1",
"typescript": "^2.7.2"
"typescript": "^3.4.5"
}
}

View File

@@ -34,6 +34,7 @@ const app = express();
// Connect to MongoDB
const mongoUrl = MONGODB_URI;
(<any>mongoose).Promise = bluebird;
mongoose.connect(mongoUrl, { useMongoClient: true }).then(
() => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ },
).catch(err => {

View File

@@ -4,7 +4,7 @@ import passportFacebook from "passport-facebook";
import _ from "lodash";
// import { User, UserType } from '../models/User';
import { default as User } from "../models/User";
import { User } from "../models/User";
import { Request, Response, NextFunction } from "express";
const LocalStrategy = passportLocal.Strategy;

View File

@@ -2,7 +2,7 @@ import async from "async";
import crypto from "crypto";
import nodemailer from "nodemailer";
import passport from "passport";
import { default as User, UserModel, AuthToken } from "../models/User";
import { User, UserDocument, AuthToken } from "../models/User";
import { Request, Response, NextFunction } from "express";
import { IVerifyOptions } from "passport-local";
import { WriteError } from "mongodb";
@@ -37,7 +37,7 @@ export let postLogin = (req: Request, res: Response, next: NextFunction) => {
return res.redirect("/login");
}
passport.authenticate("local", (err: Error, user: UserModel, info: IVerifyOptions) => {
passport.authenticate("local", (err: Error, user: UserDocument, info: IVerifyOptions) => {
if (err) { return next(err); }
if (!user) {
req.flash("errors", info.message);
@@ -138,7 +138,7 @@ export let postUpdateProfile = (req: Request, res: Response, next: NextFunction)
return res.redirect("/account");
}
User.findById(req.user.id, (err, user: UserModel) => {
User.findById(req.user.id, (err, user: UserDocument) => {
if (err) { return next(err); }
user.email = req.body.email || "";
user.profile.name = req.body.name || "";
@@ -174,7 +174,7 @@ export let postUpdatePassword = (req: Request, res: Response, next: NextFunction
return res.redirect("/account");
}
User.findById(req.user.id, (err, user: UserModel) => {
User.findById(req.user.id, (err, user: UserDocument) => {
if (err) { return next(err); }
user.password = req.body.password;
user.save((err: WriteError) => {
@@ -276,7 +276,7 @@ export let postReset = (req: Request, res: Response, next: NextFunction) => {
});
});
},
function sendResetPasswordEmail(user: UserModel, done: Function) {
function sendResetPasswordEmail(user: UserDocument, done: Function) {
const transporter = nodemailer.createTransport({
service: "SendGrid",
auth: {
@@ -350,7 +350,7 @@ export let postForgot = (req: Request, res: Response, next: NextFunction) => {
});
});
},
function sendForgotPasswordEmail(token: AuthToken, user: UserModel, done: Function) {
function sendForgotPasswordEmail(token: AuthToken, user: UserDocument, done: Function) {
const transporter = nodemailer.createTransport({
service: "SendGrid",
auth: {

View File

@@ -2,7 +2,7 @@ import bcrypt from "bcrypt-nodejs";
import crypto from "crypto";
import mongoose from "mongoose";
export type UserModel = mongoose.Document & {
export type UserDocument = mongoose.Document & {
email: string,
password: string,
passwordResetToken: string,
@@ -88,6 +88,4 @@ userSchema.methods.gravatar = function (size: number) {
return `https://gravatar.com/avatar/${md5}?s=${size}&d=retro`;
};
// export const User: UserType = mongoose.model<UserType>('User', userSchema);
const User = mongoose.model("User", userSchema);
export default User;
export const User = mongoose.model<UserDocument>("User", userSchema);

View File

@@ -21,6 +21,10 @@ if (!SESSION_SECRET) {
}
if (!MONGODB_URI) {
logger.error("No mongo connection string. Set MONGODB_URI environment variable.");
if (prod) {
logger.error("No mongo connection string. Set MONGODB_URI environment variable.");
} else {
logger.error("No mongo connection string. Set MONGODB_URI_LOCAL environment variable.");
}
process.exit(1);
}