This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
2 changed files
with
44 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## wfm-user example | ||
|
||
### Running example | ||
|
||
ts-node example/index.ts | ||
|
||
To test example execute in your console | ||
|
||
curl http://localhost:3000/api/users?filter=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,35 @@ | ||
import { getLogger } from '@raincatcher/logger'; | ||
import * as Bluebird from 'bluebird'; | ||
import * as express from 'express'; | ||
import * as path from 'path'; | ||
import { User, UserController, UsersRepository } from '../src/index'; | ||
|
||
const app = express(); | ||
|
||
/** | ||
* Simplified example UsersRepository. | ||
* Implementation can fetch users from databases, LDAP etc. | ||
*/ | ||
class ExampleRepository implements UsersRepository { | ||
public retrieveUsers(filter: string, limit: number): Bluebird<User[]> { | ||
const exampleUser = { id: 1, name: 'Example User' }; | ||
return Bluebird.resolve([exampleUser]); | ||
} | ||
} | ||
|
||
// Create repository | ||
const repository = new ExampleRepository(); | ||
// Create api | ||
const api = new UserController(repository); | ||
|
||
// Mount api into path | ||
app.use('/api/users', api.buildRouter()); | ||
|
||
app.use(function(err: any, req: express.Request, res: express.Response, next: any) { | ||
getLogger().error(err); | ||
res.status(500).send(err); | ||
}); | ||
|
||
app.listen(3000, function() { | ||
getLogger().info('Example auth app listening on port 3000'); | ||
}); |