Skip to content
This repository was archived by the owner on Jan 20, 2020. It is now read-only.

Commit 7c952ab

Browse files
author
Luciano Nooijen
committed
Improved folder structure
1 parent dd6c887 commit 7c952ab

25 files changed

+101
-11
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ to start using the package, create a new instance of the NodeBlog class
4444

4545
```js
4646
const nodeBlogConfig = {
47+
client: 'YOUR_DB_CLIENT' // for more info, see https://knexjs.org/
4748
host: 'YOUR_DB_HOST'
4849
database: 'YOUR_DB_NAME'
4950
user: 'YOUR_DB_USER'
5051
pass: 'YOUR_DB_PASS'
52+
debug: true || false
5153
};
5254
const nodeBlog = new NodeBlog(nodeBlogConfig);
5355
```
@@ -80,8 +82,27 @@ For development, the following commands are available:
8082
| `yarn run migrate` | Migrates your database (normal one, not test database) to the most recent migration, seeds will not be ran |
8183
| `yarn run reinstall` | Deletes the `node_modules/` folder and reinstalls everything, if you get some stange dependency errors, run this command |
8284

85+
### Folder structure
86+
87+
```md
88+
├── controllers Controller logic for the module based API
89+
├── database All database related files
90+
│   ├── migrations
91+
│   └── seeds
92+
├── helpers Helper files, for example: logger, database instance
93+
├── server Server configuration
94+
│   ├── controllers
95+
│   ├── middleware
96+
│   │   └── modules
97+
│   └── routes
98+
└── tests All tests written
99+
├── config
100+
└── database
101+
```
102+
83103
# Todo
84104

105+
* Add Yarn seed command
85106
* Add authentication, password hashing -> also improve seed scripts
86107
* Add auth routes to get JWT
87108
* Using https://thejackalofjavascript.com/architecting-a-restful-node-js-app/
@@ -92,6 +113,7 @@ For development, the following commands are available:
92113
* Make sure the application is available both as a NPM module and as a standalone service
93114
* Integrate https://github.com/semantic-release/semantic-release
94115
* Split up standalone and module
116+
* Add XML feed
95117

96118
## Notes
97119

controllers/controllers.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/* eslint-disable global-require */
1+
const Authors = require('./authors');
2+
const Users = require('./users');
3+
// const Categories = require('./categories');
4+
// const Posts = require('./posts');
25

36
module.exports = {
4-
Status: require('./status-controller'),
5-
Authors: require('./authors-controller'),
6-
Users: require('./users-controller'),
7-
Categories: require('./categories-controller'),
8-
Posts: require('./posts-controller'),
7+
Authors,
8+
Users,
99
};
File renamed without changes.

knexfile-test.js

+4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ module.exports = {
2626
},
2727
migrations: {
2828
tableName: 'knex_migrations',
29+
directory: './database/migrations',
2930
},
3031
debug,
3132
asyncStackTraces: debug,
33+
seeds: {
34+
directory: './database/seeds',
35+
},
3236
};

knexfile.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: Improve file: https://knexjs.org/#knexfile, move file to ./database
2+
13
require('dotenv').config();
24

35
// eslint-disable-next-line
@@ -26,7 +28,11 @@ module.exports = {
2628
},
2729
migrations: {
2830
tableName: 'knex_migrations',
31+
directory: './database/migrations',
2932
},
3033
debug,
3134
asyncStackTraces: debug,
35+
seeds: {
36+
directory: './database/seeds',
37+
},
3238
};

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"node": ">=8.0.0"
2626
},
2727
"scripts": {
28-
"dev": "nodemon",
29-
"start": "node server.js",
28+
"dev": "nodemon server/server.js",
29+
"start": "node server/server.js",
3030
"lint": "eslint --ext .jsx,.js,.ts .",
3131
"test": "NODE_ENV=TEST jest -i",
3232
"test:watch": "NODE_ENV=TEST jest -i --watch",

app.js renamed to server/app.js

File renamed without changes.

controllers/authors-controller.js renamed to server/controllers/authors-server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { listAuthors } = require('./authors');
1+
const { listAuthors } = require('../../controllers/authors');
22

33
const list = async (req, res) => {
44
const authors = await listAuthors();

server/controllers/index.js

Whitespace-only changes.
File renamed without changes.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const Status = require('./status-server');
2+
const Authors = require('./authors-server');
3+
const Users = require('./users-server');
4+
const Categories = require('./categories-server');
5+
const Posts = require('./posts-server');
6+
7+
module.exports = {
8+
Status,
9+
Authors,
10+
Users,
11+
Categories,
12+
Posts,
13+
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

server.js renamed to server/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if (ENABLE_SQREEN === 'true' && NODE_ENV !== 'TEST') require('sqreen');
55
/* eslint-enable */
66

77
const app = require('./app');
8-
const logger = require('./helpers/logger');
8+
const logger = require('../helpers/logger');
99

1010
app.listen(PORT, () => {
1111
logger.info(`Server listening on port ${PORT}`); // eslint-disable-line

temp.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const controllers = require('./controllers');
2+
3+
const authors = {
4+
getAuthors: controllers.Authors.list,
5+
getAuthor: controllers.Authors.show,
6+
addAuthor: controllers.Authors.create,
7+
updateAuthor: controllers.Authors.update,
8+
removeAuthor: controllers.Authors.remove,
9+
};
10+
11+
const users = {
12+
getUsers: controllers.Users.list,
13+
getUser: controllers.Users.show,
14+
addUser: controllers.Users.create,
15+
updateUser: controllers.Users.update,
16+
removeUser: controllers.Users.remove,
17+
};
18+
19+
const categories = {
20+
getCategories: controllers.Categories.list,
21+
getCategory: controllers.Categories.show,
22+
addCategory: controllers.Categories.create,
23+
updateCategory: controllers.Categories.update,
24+
removeCategory: controllers.Categories.remove,
25+
};
26+
27+
const posts = {
28+
getPosts: controllers.Posts.list,
29+
getPost: controllers.Posts.show,
30+
addPost: controllers.Posts.create,
31+
updatePost: controllers.Posts.update,
32+
removePost: controllers.Posts.remove,
33+
};
34+
35+
const test = {
36+
...controllers,
37+
};
38+
console.log(test);
39+
40+
module.exports = {
41+
...authors,
42+
...users,
43+
...categories,
44+
...posts,
45+
};

tests/supertest.test-archive.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Until this has been resolved, this file will be archived for later use.
33

44
const request = require('supertest');
5-
const app = require('../app');
5+
const app = require('../server/app');
66

77
describe('Test the status paths', () => {
88
test('The GET / route should give status code 200', async () => {

0 commit comments

Comments
 (0)