Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit 474f045

Browse files
committed
initial setting
1 parent 315fc4c commit 474f045

File tree

21 files changed

+72
-315
lines changed

21 files changed

+72
-315
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ JWT_SECRET ='p4sta.w1th-b0logn3s3-s@uce'
44

55
# Mongo DB
66
# Local development
7-
MONGODB_URI='mongodb://localhost/bulletproof-nodejs'
7+
MONGODB_URI='localhost:12345'
88

99
# Port
1010
PORT=3000

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ npm-debug.log*
1010
yarn-debug.log*
1111
yarn-error.log*
1212
.env
13-
build
13+
build
14+
.ssh

.now/README.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
> Why do I have a folder named ".now" in my project?
2+
The ".now" folder is created when you link a directory to a ZEIT Now project.
3+
4+
> What does the "project.json" file contain?
5+
The "project.json" file contains:
6+
- The ID of the ZEIT Now project that you linked ("projectId")
7+
- The ID of the user or team your ZEIT Now project is owned by ("orgId")
8+
9+
> Should I commit the ".now" folder?
10+
No, you should not share the ".now" folder with anyone.
11+
Upon creation, it will be automatically added to your ".gitignore" file.

.now/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"orgId":"ZEwQNW2UefGhZgV7QtjeIw3K","projectId":"Qmbr8bbrVmw85Q3L1PVZpdJu28ispomNbTRsC7Bn1DxyXT"}

README.md

Lines changed: 2 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,3 @@
1-
# Bulletproof Node.js architecture 🛡️
1+
# react-11th-practice-server
22

3-
This is the example repository from the blog post ['Bulletproof node.js project architecture'](https://softwareontheroad.com/ideal-nodejs-project-structure?utm_source=github&utm_medium=readme)
4-
5-
Please read the blog post in order to have a good understanding of the server architecture.
6-
7-
Also, I added lots of comments to the code that are not in the blog post, because they explain the implementation and the reason behind the choices of libraries and some personal opinions and some bad jokes.
8-
9-
The API by itself doesn't do anything fancy, it's just a user CRUD with authentication capabilities.
10-
Maybe we can transform this into something useful, a more advanced example, just open an issue and let's discuss the future of the repo.
11-
12-
## Development
13-
14-
We use `node` version `10.15.0`
15-
16-
```
17-
nvm install 10.15.0
18-
```
19-
20-
```
21-
nvm use 10.15.0
22-
```
23-
24-
The first time, you will need to run
25-
26-
```
27-
npm install
28-
```
29-
30-
Then just start the server with
31-
32-
```
33-
npm run start
34-
```
35-
It uses nodemon for livereloading :peace-fingers:
36-
37-
# API Validation
38-
39-
By using celebrate the req.body schema becomes clary defined at route level, so even frontend devs can read what an API endpoint expects without need to writting a documentation that can get outdated quickly.
40-
41-
```js
42-
route.post('/signup',
43-
celebrate({
44-
body: Joi.object({
45-
name: Joi.string().required(),
46-
email: Joi.string().required(),
47-
password: Joi.string().required(),
48-
}),
49-
}),
50-
controller.signup)
51-
```
52-
53-
**Example error**
54-
55-
```json
56-
{
57-
"errors": {
58-
"message": "child \"email\" fails because [\"email\" is required]"
59-
}
60-
}
61-
```
62-
63-
[Read more about celebrate here](https://github.com/arb/celebrate) and [the Joi validation API](https://github.com/hapijs/joi/blob/v15.0.1/API.md)
64-
65-
# Roadmap
66-
- [x] API Validation layer (Celebrate+Joi)
67-
- [ ] Unit tests examples
68-
- [ ] [Cluster mode](https://softwareontheroad.com/nodejs-scalability-issues?utm_source=github&utm_medium=readme)
69-
- [x] The logging _'layer'_
70-
- [ ] Add agenda dashboard
71-
- [x] Continuous integration with CircleCI 😍
72-
- [ ] Deploys script and docs for AWS Elastic Beanstalk and Heroku
73-
- [ ] Integration test with newman 😉
74-
- [ ] Instructions on typescript debugging with VSCode
75-
76-
77-
# FAQ
78-
79-
## Where should I put the FrontEnd code? Is this a good backend for Angular or React or Vue or _whatever_ ?
80-
81-
[It's not a good idea to have node.js serving static assets a.k.a the frontend](https://softwareontheroad.com/nodejs-scalability-issues?utm_source=github&utm_medium=readme)
82-
83-
Also, I don't wanna take part in frontend frameworks wars 😅
84-
85-
Just use the frontend framework you like the most _or hate the least_. It will work 😁
86-
87-
## Don't you think you can add X layer to do Y? Why do you still use express if the Serverless Framework is better and it's more reliable?
88-
89-
I know this is not a perfect architecture but it's the most scalable that I know with less code and headache that I know.
90-
91-
It's meant for small startups or one-developer army projects.
92-
93-
I know if you start moving layers into another technology, you will end up with your business/domain logic into npm packages, your routing layer will be pure AWS Lambda functions and your data layer a combination of DynamoDB, Redis, maybe redshift, and Agolia.
94-
95-
Take a deep breath and go slowly, let the business grow and then scale up your product. You will need a team and talented developers anyway.
3+
리액트 미션 진행시 사용하기 위한 실습용 서버

package-lock.json

Lines changed: 11 additions & 19 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 & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "bulletproof-nodejs",
2+
"name": "react-11th-practice-server",
33
"version": "1.0.0",
4-
"description": "Bulletproof node.js",
4+
"description": "for ceos 11th react fetch practice",
55
"main": "src/app.ts",
66
"scripts": {
77
"build": "tsc",
@@ -16,23 +16,17 @@
1616
},
1717
"repository": {
1818
"type": "git",
19-
"url": "git+https://github.com/santiq/bulletproof-nodejs.git"
19+
"url": "git+https://github.com/CEOS-Developers/react-11th-practice-server.git"
2020
},
2121
"keywords": [
22-
"boilerplay",
23-
"cron",
24-
"jobs",
25-
"js",
26-
"javascript",
22+
"ceos",
2723
"typescript",
2824
"node",
2925
"express"
3026
],
31-
"author": "Santiago Quinteros",
27+
"author": "Choi Sumin",
3228
"license": "ISC",
3329
"dependencies": {
34-
"agenda": "^2.0.2",
35-
"agendash": "^1.0.0",
3630
"argon2": "^0.21.0",
3731
"body-parser": "^1.18.2",
3832
"celebrate": "^9.1.0",
@@ -57,7 +51,6 @@
5751
"winston": "^3.2.1"
5852
},
5953
"devDependencies": {
60-
"@types/agenda": "^2.0.4",
6154
"@types/express": "^4.16.0",
6255
"@types/jest": "^23.3.8",
6356
"@types/lodash": "^4.14.118",
@@ -77,7 +70,7 @@
7770
"typescript": "^3.1.3"
7871
},
7972
"bugs": {
80-
"url": "https://github.com/santiq/bulletproof-nodejs/issues"
73+
"url": "https://github.com/CEOS-Developers/react-11th-practice-server/issues"
8174
},
82-
"homepage": "https://github.com/santiq/bulletproof-nodejs#readme"
75+
"homepage": "https://github.com/CEOS-Developers/react-11th-practice-server#readme"
8376
}

src/api/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { Router } from 'express';
22
import auth from './routes/auth';
33
import user from './routes/user';
4-
import agendash from './routes/agendash';
54

65
// guaranteed to get dependencies
76
export default () => {
8-
const app = Router();
9-
auth(app);
10-
user(app);
11-
agendash(app);
7+
const app = Router();
8+
auth(app);
9+
user(app);
1210

13-
return app
14-
}
11+
return app;
12+
};

src/api/middlewares/attachCurrentUser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { Container } from 'typedi';
22
import mongoose from 'mongoose';
33
import { IUser } from '../../interfaces/IUser';
4+
import { getLogger } from '../../loaders/dependencyInjector';
45

56
/**
6-
* Attach user to req.user
7+
* Attach user to req.currentUser
78
* @param {*} req Express req Object
89
* @param {*} res Express res Object
910
* @param {*} next Express next Function
1011
*/
1112
const attachCurrentUser = async (req, res, next) => {
12-
const Logger = Container.get('logger');
13+
const Logger = getLogger();
1314
try {
1415
const UserModel = Container.get('userModel') as mongoose.Model<IUser & mongoose.Document>;
1516
const userRecord = await UserModel.findById(req.token._id);

src/api/routes/agendash.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)