forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kamil.mysliwiec
committed
Feb 4, 2017
1 parent
73997f5
commit d3abc2d
Showing
152 changed files
with
3,496 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
|
||
# IDE | ||
/.idea | ||
/.awcache | ||
|
||
# misc | ||
npm-debug.log | ||
npm-debug.log | ||
|
||
# example | ||
/.example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(The MIT License) | ||
|
||
Copyright (c) 2017 Kamil Myśliwiec <http://kamilmysliwiec.com> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[![Nest Logo](http://kamilmysliwiec.com/public/nest-logo.png)](http://kamilmysliwiec.com/) | ||
|
||
Modern, fast, powerful web framework for [node](http://nodejs.org). | ||
|
||
[![NPM Version][npm-image]][npm-url] | ||
[![NPM Downloads][downloads-image]][downloads-url] | ||
[![Linux Build][travis-image]][travis-url] | ||
[![Windows Build][appveyor-image]][appveyor-url] | ||
|
||
## License | ||
|
||
[MIT](LICENSE) | ||
|
||
[npm-image]: https://img.shields.io/npm/v/nest.js.svg | ||
[npm-url]: https://npmjs.org/package/nest.js | ||
[downloads-image]: https://img.shields.io/npm/dm/nest.js.svg | ||
[downloads-url]: https://npmjs.org/package/nest.js | ||
[travis-image]: https://img.shields.io/travis/nest.jsjs/nest.js/master.svg?label=linux | ||
[travis-url]: https://travis-ci.org/nest.jsjs/nest.js | ||
[appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/nest.js/master.svg?label=windows | ||
[appveyor-url]: https://ci.appveyor.com/project/dougwilson/nest.js | ||
[coveralls-image]: https://img.shields.io/coveralls/nest.jsjs/nest.js/master.svg | ||
[coveralls-url]: https://coveralls.io/r/nest.jsjs/nest.js?branch=master | ||
[gratipay-image-visionmedia]: https://img.shields.io/gratipay/visionmedia.svg | ||
[gratipay-url-visionmedia]: https://gratipay.com/visionmedia/ | ||
[gratipay-image-dougwilson]: https://img.shields.io/gratipay/dougwilson.svg | ||
[gratipay-url-dougwilson]: https://gratipay.com/dougwilson/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ExpressConfig } from "./config"; | ||
import { PassportJWTConfig } from "./config/passport-jwt.config"; | ||
import { NestApplication } from "./../src/"; | ||
|
||
export class Application implements NestApplication { | ||
|
||
constructor(private app) { | ||
ExpressConfig.setupConfig(this.app); | ||
PassportJWTConfig.setupConfig(this.app); | ||
} | ||
|
||
public start() { | ||
console.log("star t"); | ||
this.app.listen(3030, () => { | ||
console.log("Nest Application listen on port:", 3030); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class ApplicationConfig { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Application } from "express"; | ||
import * as bodyParser from "body-parser"; | ||
import * as logger from "morgan"; | ||
|
||
export class ExpressConfig { | ||
|
||
static setupConfig(app: Application) { | ||
app.use(logger("dev")); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
|
||
// Add headers | ||
app.use(function (req, res, next) { | ||
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:4200'); | ||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); | ||
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); | ||
next(); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./app.config"; | ||
export * from "./express.config"; | ||
export * from "./passport-jwt.config"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import * as _ from "lodash"; | ||
import { Application } from "express"; | ||
import * as passport from "passport"; | ||
import { ExtractJwt, Strategy, StrategyOptions } from "passport-jwt"; | ||
|
||
var users = [ | ||
{ | ||
id: 1, | ||
name: 'jonathanmh', | ||
password: '%2yx4' | ||
}, | ||
{ | ||
id: 2, | ||
name: 'test', | ||
password: 'test' | ||
} | ||
]; | ||
|
||
export class PassportJWTConfig { | ||
static readonly secretKey = "XD"; | ||
|
||
static readonly jwtOptions: StrategyOptions = { | ||
jwtFromRequest: ExtractJwt.fromAuthHeader(), | ||
secretOrKey: PassportJWTConfig.secretKey, | ||
}; | ||
|
||
static setupConfig(app: Application) { | ||
this.init(); | ||
app.use(passport.initialize()); | ||
} | ||
|
||
static init() { | ||
|
||
var strategy = new Strategy(this.jwtOptions, (payload, next) => { | ||
console.log('payload received', payload); | ||
|
||
var user = users[_.findIndex(users, {id: payload.id})]; | ||
console.log(user); | ||
next(null, user || false); | ||
}); | ||
|
||
passport.use(strategy); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as mongoose from "mongoose"; | ||
mongoose.connect("mongodb://localhost:27017/tracker", { | ||
server: { | ||
socketOptions: { | ||
socketTimeoutMS: 0, | ||
connectTimeoutMS: 0 | ||
} | ||
} | ||
}); | ||
export { mongoose as db }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as mongoose from "mongoose"; | ||
import { db } from "./db"; | ||
|
||
interface IUser extends mongoose.Document { | ||
name: string; | ||
heh: any; | ||
} | ||
|
||
type UserType = IUser & mongoose.Document; | ||
|
||
export const User = db.model<UserType>('User', new mongoose.Schema({ | ||
name : {type : String, required : true}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { UsersModule } from "./users/users.module"; | ||
import { AuthModule } from "./auth/auth.module"; | ||
import { Module } from "./../../src/"; | ||
|
||
@Module({ | ||
modules: [ | ||
UsersModule, | ||
AuthModule | ||
] | ||
}) | ||
export class ApplicationModule { | ||
configure() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { AuthRoute } from "./login.route"; | ||
import { SharedModule } from "../shared.module"; | ||
import { Module } from "./../../../src/"; | ||
|
||
@Module({ | ||
modules: [ | ||
SharedModule, | ||
], | ||
controllers: [ | ||
AuthRoute | ||
], | ||
components: [ | ||
] | ||
}) | ||
export class AuthModule { | ||
configure() { | ||
console.log("auth configured"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import * as _ from "lodash"; | ||
import * as jwt from "jsonwebtoken"; | ||
import { Request, Response, NextFunction } from "express"; | ||
import { PassportJWTConfig } from "../../config/passport-jwt.config"; | ||
import { Controller, RequestMethod, RequestMapping } from "./../../../src/"; | ||
|
||
var users = [ | ||
{ | ||
id: 1, | ||
name: 'jonathanmh', | ||
password: '%2yx4' | ||
}, | ||
{ | ||
id: 2, | ||
name: 'test', | ||
password: 'test' | ||
} | ||
]; | ||
|
||
@Controller({ path: "login" }) | ||
export class AuthRoute { | ||
|
||
constructor() {} | ||
|
||
@RequestMapping({ path: "/", method: RequestMethod.POST }) | ||
fetchToken(req: Request, res: Response, next: NextFunction) { | ||
const { name, password } = req.body; | ||
|
||
const user = users[_.findIndex(users, {name: name})]; | ||
if (!user){ | ||
res.status(401).json({message:"no such user found"}); | ||
} | ||
|
||
if(user.password === password) { | ||
const payload = {id: user.id}; | ||
const token = jwt.sign(payload, PassportJWTConfig.secretKey); | ||
res.json({message: "ok", token: token}); | ||
} | ||
else { | ||
res.status(401).json({message:"passwords did not match"}); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
import { SharedService } from "./shared.service"; | ||
import { Module } from "./../../src/"; | ||
|
||
@Module({ | ||
components: [ | ||
SharedService, | ||
], | ||
exports: [ | ||
SharedService, | ||
] | ||
}) | ||
export class SharedModule { | ||
configure() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Component } from "./../../src/"; | ||
import { Subject } from "rxjs"; | ||
|
||
@Component() | ||
export class SharedService { | ||
public stream$ = new Subject<string>(); | ||
constructor() { | ||
setTimeout(() => { | ||
this.stream$.next("XDDD"); | ||
}, 3000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//import { User } from "../../models/user"; | ||
import { SharedService } from "../shared.service"; | ||
import { Component, RequestMapping } from "./../../../src/"; | ||
import { UsersGateway } from "./users.gateway"; | ||
|
||
import { Subject } from "rxjs"; | ||
|
||
@Component() | ||
export class UsersQueryService { | ||
|
||
public stream$ = new Subject<string>(); | ||
static get dependencies() { | ||
return [ UsersGateway, SharedService ]; | ||
} | ||
|
||
constructor(private usersGateway: UsersGateway, private shared: SharedService) { | ||
this.shared.stream$.subscribe((xd) => { | ||
console.log("ONCE"); | ||
this.stream$.next(xd); | ||
}); | ||
} | ||
/* | ||
getAllUsers(): Promise<any> { | ||
return new Promise((resolve) => { | ||
User.find((err, res) => { | ||
if(err) { | ||
throw new Error(err); | ||
} | ||
resolve(res); | ||
}); | ||
}); | ||
}*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
import { RequestMapping, RequestMethod} from "./../../../src/"; | ||
import { UsersQueryService } from "./users-query.service"; | ||
import { Controller } from "./../../../src/"; | ||
|
||
@Controller({ path: "users" }) | ||
export class UsersSecRoute { | ||
|
||
constructor(private usersQueryService: UsersQueryService) { | ||
this.usersQueryService.stream$.subscribe((xd) => { | ||
console.log(xd); | ||
}); | ||
} | ||
|
||
/*@RequestMapping({ | ||
path: "/", | ||
method: RequestMethod.GET | ||
}) | ||
async getAllUsers(req: Request, res: Response, next: NextFunction) { | ||
try { | ||
const users = await this.usersQueryService.getAllUsers(); | ||
res.status(201).json(users); | ||
next(); | ||
} | ||
catch(e) { | ||
next(e.message); | ||
} | ||
}*/ | ||
|
||
} | ||
|
Oops, something went wrong.