Skip to content

Commit 8c7d6b8

Browse files
committed
first commit
0 parents  commit 8c7d6b8

17 files changed

+422
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
extends: 'airbnb-base',
3+
plugins: ['prettier'],
4+
rules: {
5+
'prettier/prettier': 'error'
6+
}
7+
};

.gitignore

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
yarn.lock
57+
58+
# dotenv environment variables file
59+
.env
60+

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Contributing
2+
3+
1. Fork it!
4+
2. Create your feature branch: `git checkout -b my-new-feature`
5+
3. Commit your changes: `git commit -m 'Add some feature'`
6+
4. Push to the branch: `git push origin my-new-feature`
7+
8+
*Remember that we have a pre-push hook with steps that analyzes and prevents mistakes.*
9+
10+
**After your pull request is merged**, you can safely delete your branch.

LICENSE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2017 - Emerson Luiz
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Nodejs Typescript Boilerplate
2+
3+
This is a simple NodeJS template using Typescript.
4+
5+
## Getting Started
6+
7+
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
8+
9+
### Prerequisites
10+
11+
What things you need to install the software and how to install them
12+
13+
```
14+
Give examples
15+
```
16+
17+
### Installing
18+
19+
A step by step series of examples that tell you have to get a development env running
20+
21+
Say what the step will be
22+
23+
```
24+
Give the example
25+
```
26+
27+
And repeat
28+
29+
```
30+
until finished
31+
```
32+
33+
End with an example of getting some data out of the system or using it for a little demo
34+
35+
## Running the tests
36+
37+
Explain how to run the automated tests for this system
38+
39+
### Break down into end to end tests
40+
41+
Explain what these tests test and why
42+
43+
```
44+
Give an example
45+
```
46+
47+
### And coding style tests
48+
49+
Explain what these tests test and why
50+
51+
```
52+
Give an example
53+
```
54+
55+
## Deployment
56+
57+
Add additional notes about how to deploy this on a live system
58+
59+
## Built With
60+
61+
* [Dropwizard](http://www.dropwizard.io/1.0.2/docs/) - The web framework used
62+
* [Maven](https://maven.apache.org/) - Dependency Management
63+
* [ROME](https://rometools.github.io/rome/) - Used to generate RSS Feeds
64+
65+
## Contributing
66+
67+
Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.
68+
69+
## Versioning
70+
71+
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags).
72+
73+
## Authors
74+
75+
* **Billie Thompson** - *Initial work* - [PurpleBooth](https://github.com/PurpleBooth)
76+
77+
See also the list of [contributors](https://github.com/your/project/contributors) who participated in this project.
78+
79+
## License
80+
81+
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
82+
83+
## Acknowledgments
84+
85+
* Hat tip to anyone who's code was used
86+
* Inspiration
87+
* etc

package.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "nodejs-ts",
3+
"version": "1.0.0",
4+
"description": "A simple boilerplate for NodeJS using Typescript projects",
5+
"main": "index.js",
6+
"license": "MIT",
7+
"author": {
8+
"name": "Emerson Luiz",
9+
"email": "[email protected]",
10+
"url": "https://github.com/eluizbr"
11+
},
12+
"engines": {
13+
"node": "~8.9.1",
14+
"npm": "5.5.1"
15+
},
16+
"scripts": {
17+
"heroku-prebuild":
18+
"npm install --only=dev && node_modules/.bin/tsc -p . && npm run makeDevDoc",
19+
"dev": "export NODE_ENV='devel' && nodemon --exec ts-node src/index.ts",
20+
"prod":
21+
"export NODE_ENV='production' && nodemon --exec ts-node src/index.ts",
22+
"build": "tsc -p . && apidoc -i src -o build/public/doc",
23+
"makeDoc": "node_modules/.bin/apidoc -i src -o src/public/doc",
24+
"copyApp": "cd src/public && cp -rfv app ../../build/public",
25+
"makeDevDoc":
26+
"node_modules/.bin/apidoc -i src -o build/public/doc && npm run copyApp && ls -lisa build/public/",
27+
"start": "node build/index.js"
28+
},
29+
"devDependencies": {
30+
"@types/bcryptjs": "^2.4.1",
31+
"@types/body-parser": "^1.16.8",
32+
"@types/compression": "^0.0.35",
33+
"@types/cors": "^2.8.3",
34+
"@types/express": "^4.0.39",
35+
"@types/express-jwt": "^0.0.38",
36+
"@types/express-session": "^1.15.6",
37+
"@types/helmet": "^0.0.37",
38+
"@types/mongodb": "^2.2.15",
39+
"@types/mongoose": "^4.7.27",
40+
"@types/morgan": "^1.7.35",
41+
"@types/node": "^8.0.53",
42+
"@types/passport": "^0.4.1",
43+
"apidoc": "^0.17.6",
44+
"eslint": "^4.11.0",
45+
"eslint-plugin-prettier": "^2.3.1",
46+
"prettier": "^1.8.2",
47+
"ts-node": "^3.3.0",
48+
"tslint": "^5.8.0",
49+
"typescript": "^2.6.1"
50+
},
51+
"dependencies": {
52+
"bcryptjs": "^2.4.3",
53+
"body-parser": "^1.18.2",
54+
"compression": "^1.7.1",
55+
"cors": "^2.8.4",
56+
"express": "^4.16.2",
57+
"express-jwt": "^5.3.0",
58+
"express-session": "^1.15.6",
59+
"helmet": "^3.9.0",
60+
"mongoose": "^4.13.4",
61+
"mongoose-paginate": "^5.0.3",
62+
"morgan": "^1.9.0",
63+
"passport": "^0.4.0",
64+
"passport-local": "^1.0.0"
65+
}
66+
}

src/config/config-dev.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export = {
2+
mongoDB: 'mongodb://ecobonuz:[email protected]:57624/moeda',
3+
jwtSecret: '9V2ek8KEjUB814ewYKqa38Td9XK15rNJraBJAhvasH5WtV6hSp',
4+
modalTimer: 5000,
5+
emailHost: 'email-smtp.us-east-1.amazonaws.com',
6+
emailPort: 465,
7+
emailUser: 'AKIAIEG2IQRVHTIBKZPQ',
8+
emailPass: 'AigbxpB4vz/SByBgR3u3FWoxWZGazNvNCGW4sw+PRE1i',
9+
queueServer: 'amqp://kkiigncq:[email protected]/kkiigncq',
10+
};

src/config/config-prod.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export = {
2+
mongoDB: 'mongodb://ecobonuz:[email protected]:57624/moeda',
3+
jwtSecret: '9V2ek8KEjUB814ewYKqa38Td9XK15rNJraBJAhvasH5WtV6hSp',
4+
modalTimer: 5000,
5+
emailHost: 'email-smtp.us-east-1.amazonaws.com',
6+
emailPort: 465,
7+
emailUser: 'AKIAIEG2IQRVHTIBKZPQ',
8+
emailPass: 'AigbxpB4vz/SByBgR3u3FWoxWZGazNvNCGW4sw+PRE1i',
9+
queueServer: 'amqp://kkiigncq:[email protected]/kkiigncq',
10+
};

src/config/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
process.env.NODE_ENV === 'production'
2+
? (module.exports = require('./config-prod'))
3+
: (module.exports = require('./config-dev'));

src/config/unlessPath.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const unlessPath = {
2+
path: [
3+
{ url: '/api/v1/login', methods: ['POST'] },
4+
{ url: '/doc', methods: ['GET'] },
5+
{ url: '/app', methods: ['GET', 'POST', 'PATCH', 'DELETE'] },
6+
],
7+
};

src/index.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import * as BodyParser from 'body-parser';
2+
import * as cors from 'cors';
3+
import { Application, NextFunction, Request, Response } from 'express';
4+
import * as express from 'express';
5+
import * as jwt from 'express-jwt';
6+
import * as session from 'express-session';
7+
import * as helmet from 'helmet';
8+
import * as mongoose from 'mongoose';
9+
import * as passport from 'passport';
10+
11+
import { unlessPath } from './config/unlessPath';
12+
13+
const server: Application = express();
14+
const PORT = process.env.PORT || 3000;
15+
16+
// set environment
17+
const config = require('./config');
18+
19+
/**
20+
* Node.js body parsing middleware.
21+
* https://github.com/expressjs/body-parser
22+
*/
23+
server.use(BodyParser.urlencoded({ extended: true }));
24+
server.use(BodyParser.json());
25+
26+
/**
27+
* CORS is a node.js package for providing a Connect/Express middleware that
28+
* can be used to enable CORS with various options.
29+
* https://github.com/expressjs/cors
30+
*/
31+
server.use(cors());
32+
33+
// Sessions
34+
server.use(
35+
session({ secret: config.jwtSecret, resave: true, saveUninitialized: true })
36+
);
37+
38+
// PassportJS
39+
server.use(passport.initialize());
40+
server.use(passport.session());
41+
42+
/**
43+
* Helmet helps you secure your Express apps by setting various HTTP headers.
44+
* https://github.com/helmetjs/helmet
45+
*/
46+
server.use(helmet());
47+
48+
// Mongoose
49+
(<any>mongoose).Promise = global.Promise;
50+
mongoose
51+
.connect(config.mongoDB, { useMongoClient: true })
52+
.then(() => console.log('Conected on MongoDB'), err => console.log(err));
53+
54+
// Some libs an configs, can run only in development mode.
55+
if (process.env.NODE_ENV !== 'production') {
56+
/**
57+
* HTTP request logger middleware for node.js
58+
* https://github.com/expressjs/morgan
59+
*/
60+
const morgan = require('morgan');
61+
server.use(morgan('dev'));
62+
63+
// Documentation
64+
server.use('/doc', express.static('src/public/doc'));
65+
server.use('/', express.static('src/public/app'));
66+
server.use('/app', express.static('src/public/app'));
67+
} else {
68+
// Documentation
69+
server.use('/doc', express.static('build/public/doc'));
70+
server.use('/', express.static('build/public/app'));
71+
server.use('/app', express.static('build/public/app'));
72+
73+
// Protect all routes
74+
server.use(jwt({ secret: config.jwtSecret }).unless(unlessPath));
75+
}
76+
77+
// Default error
78+
server.use(
79+
(err: ErrorEventHandler, req: Request, res: Response, next: NextFunction) => {
80+
if (err.name === 'UnauthorizedError') {
81+
res.status(401).send('login Error');
82+
}
83+
}
84+
);
85+
86+
// Run server on set port
87+
server.listen(PORT, () => {
88+
console.log(
89+
`Server running on port ${PORT} in ${process.env.NODE_ENV} mode.`
90+
);
91+
});

src/modules/users/routes/_apidoc.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @api {get} /users Lista todos os usuários
3+
* @apiName UsersList
4+
* @apiGroup Users
5+
* @apiVersion 1.0.0
6+
* @apiPermission Token
7+
* @apiHeader {String} Authorization Bearer token
8+
*
9+
*/

0 commit comments

Comments
 (0)