Skip to content

Commit 070b76d

Browse files
committed
init nuxt project and api
0 parents  commit 070b76d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+13216
-0
lines changed

Diff for: .editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

Diff for: .eslintrc.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
node: true
6+
},
7+
parserOptions: {
8+
parser: 'babel-eslint'
9+
},
10+
extends: [
11+
'@nuxtjs',
12+
'plugin:nuxt/recommended',
13+
// 'plugin:vue/essential',
14+
'eslint:recommended'
15+
],
16+
// add your custom rules here
17+
rules: {
18+
'no-console': 'off'
19+
}
20+
}

Diff for: .gitignore

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Node template
3+
# Logs
4+
/logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
10+
# Runtime data
11+
pids
12+
*.pid
13+
*.seed
14+
*.pid.lock
15+
16+
# Directory for instrumented libs generated by jscoverage/JSCover
17+
lib-cov
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage
21+
22+
# nyc test coverage
23+
.nyc_output
24+
25+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26+
.grunt
27+
28+
# Bower dependency directory (https://bower.io/)
29+
bower_components
30+
31+
# node-waf configuration
32+
.lock-wscript
33+
34+
# Compiled binary addons (https://nodejs.org/api/addons.html)
35+
build/Release
36+
37+
# Dependency directories
38+
node_modules/
39+
jspm_packages/
40+
41+
# TypeScript v1 declaration files
42+
typings/
43+
44+
# Optional npm cache directory
45+
.npm
46+
47+
# Optional eslint cache
48+
.eslintcache
49+
50+
# Optional REPL history
51+
.node_repl_history
52+
53+
# Output of 'npm pack'
54+
*.tgz
55+
56+
# Yarn Integrity file
57+
.yarn-integrity
58+
59+
# dotenv environment variables file
60+
.env
61+
62+
# parcel-bundler cache (https://parceljs.org/)
63+
.cache
64+
65+
# next.js build output
66+
.next
67+
68+
# nuxt.js build output
69+
.nuxt
70+
71+
# Nuxt generate
72+
dist
73+
74+
# vuepress build output
75+
.vuepress/dist
76+
77+
# Serverless directories
78+
.serverless
79+
80+
# IDE / Editor
81+
.idea
82+
83+
# Service worker
84+
sw.*
85+
86+
# macOS
87+
.DS_Store
88+
89+
# Vim swap files
90+
*.swp

Diff for: README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# pepites
2+
3+
## Build Setup
4+
5+
```bash
6+
# install dependencies
7+
$ npm install
8+
9+
# serve with hot reload at localhost:3000
10+
$ npm run dev
11+
12+
# build for production and launch server
13+
$ npm run build
14+
$ npm run start
15+
16+
# generate static project
17+
$ npm run generate
18+
```
19+
20+
For detailed explanation on how things work, check out [Nuxt.js docs](https://nuxtjs.org).

Diff for: api/app/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import http from '~/api/interfaces'
2+
3+
const startApp = async () => {
4+
return http.start()
5+
}
6+
7+
const app = startApp()
8+
9+
export default app

Diff for: api/app/services/artistsService.js

Whitespace-only changes.

Diff for: api/app/services/usersService.js

Whitespace-only changes.

Diff for: api/infra/encryption.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const crypto = require('crypto')
2+
3+
const encryptPsw = (password) => {
4+
const salt = crypto.randomBytes(16).toString('hex')
5+
const hash = crypto.pbkdf2Sync(password, salt, 100000, 64, 'sha512').toString('hex')
6+
7+
return {
8+
hash,
9+
salt
10+
}
11+
}
12+
13+
const comparePsw = (password, hash, salt) => {
14+
const hashPassword = crypto.pbkdf2Sync(password, salt, 100000, 64, 'sha512').toString('hex')
15+
16+
return hashPassword === hash
17+
}
18+
19+
const encryptFileName = (fileName) => {
20+
const nameToHash = fileName.toLowerCase()
21+
const salt = crypto.randomBytes(8).toString('hex')
22+
const hash = crypto.pbkdf2Sync(nameToHash, salt, 100, 15, 'sha512').toString('hex')
23+
24+
if (nameToHash.includes('.png')) {
25+
return `${hash}.png`
26+
}
27+
if (nameToHash.includes('.jpg')) {
28+
return `${hash}.jpg`
29+
}
30+
if (nameToHash.includes('.gif')) {
31+
return `${hash}.gif`
32+
}
33+
34+
console.error('This type of file is not supported !')
35+
}
36+
37+
export default {
38+
encryptPsw,
39+
comparePsw,
40+
encryptFileName
41+
}

Diff for: api/infra/fileUpload.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const multer = require('multer')
2+
3+
module.exports = ({ path }, encrypt, cloud) => {
4+
// const storage = multer.diskStorage({
5+
// destination: (req, file, cb) => {
6+
7+
// cb(null, path)
8+
// },
9+
// filename: (req, file, cb) => {
10+
// const fileHash = encrypt.encryptFileName(file.originalname)
11+
12+
// cb(null, fileHash)
13+
// }
14+
// })
15+
16+
// return multer({ storage })
17+
18+
return multer()
19+
}

Diff for: api/infra/jwt.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const jwt = require('jsonwebtoken')
2+
3+
module.exports = (config) => ({
4+
signin: (id) => {
5+
return jwt.sign({ id }, config.secret)
6+
},
7+
8+
verify: (token) => {
9+
return jwt.verify(token, config.secret)
10+
}
11+
})

Diff for: api/infra/logger.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const pino = require('pino')
2+
const isDev = process.env.NODE_ENV === 'development'
3+
4+
const logger = ({
5+
name = 'blog',
6+
level = 'info',
7+
enabled = true
8+
} = {}) => {
9+
return pino({
10+
name,
11+
level,
12+
enabled,
13+
useLevelLabels: true,
14+
...isDev ? { prettyPrint: { colorize: true } } : {}
15+
}, pino.destination())
16+
}
17+
18+
module.exports = logger

Diff for: api/infra/mongodb/index.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const { MongoClient } = require('mongodb')
2+
3+
let client
4+
let db
5+
6+
const connect = async ({
7+
uri,
8+
database,
9+
options
10+
}) => {
11+
if (!client) {
12+
client = new MongoClient(uri, options)
13+
14+
await client.connect()
15+
16+
db = client.db(database)
17+
}
18+
}
19+
20+
const disconnect = async () => {
21+
await client.close()
22+
}
23+
24+
export default {
25+
client: () => client,
26+
db: () => db,
27+
connect,
28+
disconnect
29+
}

Diff for: api/infra/mongodb/repositories/users.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const { ObjectID } = require('mongodb')
2+
3+
const repository = (db) => {
4+
const UsersDb = db.collection('users')
5+
6+
return {
7+
find: () => UsersDb.find().toArray(),
8+
9+
findByUsername: username => UsersDb.findOne({ username }),
10+
11+
findUserById: id => UsersDb.findOne({ _id: ObjectID(id) }),
12+
13+
updateUser: (id, newUser) => UsersDb.findOneAndUpdate(
14+
{ _id: ObjectID(id) },
15+
{ $set: newUser },
16+
{ returnOriginal: false }
17+
),
18+
19+
create: user => UsersDb.insertOne(user),
20+
21+
deleteOne: id => UsersDb.deleteOne({ _id: id }),
22+
23+
deleteUserProject: (userId, projectId) => UsersDb.updateOne(
24+
{ _id: ObjectID(userId) },
25+
{ $pull: { projectsIds: ObjectID(projectId) } },
26+
{ returnOriginal: false }
27+
),
28+
29+
addProjectToUser: (userId, projectId) => UsersDb.findOneAndUpdate(
30+
{ _id: ObjectID(userId) },
31+
{ $push: { projectsIds: ObjectID(projectId) } },
32+
{ returnOriginal: false })
33+
}
34+
}
35+
36+
module.exports = repository

Diff for: api/interfaces/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import bodyParser from 'body-parser'
2+
import helmet from 'helmet'
3+
// import cors from'cors'
4+
import express from 'express'
5+
6+
import routes from '~/api/interfaces/routes'
7+
8+
export default () => {
9+
const app = express()
10+
11+
app.use(bodyParser.json())
12+
app.use(helmet())
13+
// app.use(cors())
14+
15+
app.use('/', routes.map((route) => {
16+
return route()
17+
}))
18+
19+
return app
20+
}

Diff for: api/interfaces/routes/artists.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// const express = require('express')
2+
import express from 'express'
3+
4+
export default () => {
5+
const router = express.Router()
6+
7+
router.get('/artists', async (req, res, next) => {
8+
console.log('req ===> ', require('util').inspect(req, { colors: true, depth: 2 }))
9+
})
10+
11+
return router
12+
}

Diff for: api/interfaces/routes/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import users from './users'
2+
import artists from './artists'
3+
4+
export default [users, artists]

0 commit comments

Comments
 (0)