-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
30ce92e
commit 7b35470
Showing
16 changed files
with
1,643 additions
and
304 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,14 @@ | ||
module.exports = { | ||
env: { | ||
node: true | ||
}, | ||
extends: 'standard-with-typescript', | ||
overrides: [ | ||
], | ||
parserOptions: { | ||
ecmaVersion: 'latest' | ||
}, | ||
rules: { | ||
camelcase: [0, { ignoreDestructuring: true }] | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
node_modules | ||
.env | ||
logs | ||
logs |
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 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"endOfLine": "auto", | ||
"singleQuote": true, | ||
"semi": false, | ||
"trailingComma": "none", | ||
"bracketSpacing": true | ||
} |
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,15 @@ | ||
{ | ||
"git.ignoreMissingGitWarning": true, | ||
"eslint.options": { | ||
"extensions": [ | ||
".js" | ||
] | ||
}, | ||
"emmet.syntaxProfiles": { | ||
"javascript": "js" | ||
}, | ||
"editor.fontSize": 12, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
} | ||
} |
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 |
---|---|---|
@@ -1,22 +1,21 @@ | ||
const express = require('express'); | ||
const app = express(); | ||
const router = express.Router(); | ||
const user = require('./router/user'); | ||
const home = require('./router/home'); | ||
const upload = require('./router/upload'); | ||
const logger = require('./logger'); | ||
app.use(express.json()); | ||
|
||
router.use(function timeLog(req, res, next) { | ||
console.log('Time: ', Date.now()); | ||
next(); | ||
}); | ||
app.use('/api/user', user); | ||
app.use('/api/', upload); | ||
app.use('/', home); | ||
const express = require('express') | ||
const app = express() | ||
const router = express.Router() | ||
const user = require('./router/user') | ||
const home = require('./router/home') | ||
const upload = require('./router/upload') | ||
const logger = require('./logger') | ||
app.use(express.json()) | ||
|
||
router.use(function timeLog (req, res, next) { | ||
console.log('Time: ', Date.now()) | ||
next() | ||
}) | ||
app.use('/api/user', user) | ||
app.use('/api/', upload) | ||
app.use('/', home) | ||
|
||
app.listen('3000', () => { | ||
console.log(' serve is running at http://localhost:3000/'); | ||
logger.info(' serve is restart') | ||
}); | ||
console.log(' serve is running at http://localhost:3000/') | ||
logger.info(' serve is restart') | ||
}) |
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
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 |
---|---|---|
@@ -1,26 +1,26 @@ | ||
const log4js = require("log4js"); | ||
const log4js = require('log4js') | ||
log4js.configure({ | ||
appenders: { | ||
dateFile: { | ||
type: "dateFile", | ||
filename: "logs/logs.log", | ||
pattern: "-yyyy-MM-dd", | ||
type: 'dateFile', | ||
filename: 'logs/logs.log', | ||
pattern: '-yyyy-MM-dd', | ||
alwaysIncludePattern: true, | ||
compress: true, | ||
compress: true | ||
}, | ||
console: { | ||
type: "console", | ||
}, | ||
type: 'console' | ||
} | ||
}, | ||
categories: { | ||
default: { | ||
appenders: ["dateFile", 'console'], | ||
level: "info", | ||
}, | ||
}, | ||
}); | ||
appenders: ['dateFile', 'console'], | ||
level: 'info' | ||
} | ||
} | ||
}) | ||
|
||
const logger = log4js.getLogger(); | ||
logger.level = "debug"; | ||
const logger = log4js.getLogger() | ||
logger.level = 'debug' | ||
|
||
module.exports = logger; | ||
module.exports = logger |
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 |
---|---|---|
@@ -1,31 +1,31 @@ | ||
const tokenSalt = 'token_secret'; | ||
const jwt = require('jsonwebtoken'); | ||
const { connection } = require('../db/mysql'); | ||
const tokenSalt = 'token_secret' | ||
const jwt = require('jsonwebtoken') | ||
const { connection } = require('../db/mysql') | ||
|
||
const auth = (req, res, next) => { | ||
const raw = String(req.headers.authorization).split(' ').pop(); | ||
let tokenData = {}; | ||
try { | ||
tokenData = jwt.verify(raw, tokenSalt); | ||
} catch (e) { | ||
res.send({ | ||
code: 0, | ||
msg: '无效token', | ||
}); | ||
const raw = String(req.headers.authorization).split(' ').pop() | ||
let tokenData = {} | ||
try { | ||
tokenData = jwt.verify(raw, tokenSalt) | ||
} catch (e) { | ||
res.send({ | ||
code: 0, | ||
msg: '无效token' | ||
}) | ||
} | ||
const { id } = tokenData | ||
const sql = `select * from user where id = ${id}` | ||
connection.query(sql, (err, data) => { | ||
if (err) { | ||
res.send({ | ||
code: 0, | ||
msg: '系统错误' | ||
}) | ||
return | ||
} | ||
const { id } = tokenData; | ||
const sql = `select * from user where id = ${id}`; | ||
connection.query(sql, (err, data) => { | ||
if (err) { | ||
res.send({ | ||
code: 0, | ||
msg: '系统错误', | ||
}); | ||
return; | ||
} | ||
req.user = data[0]; | ||
next(); | ||
}); | ||
}; | ||
req.user = data[0] | ||
next() | ||
}) | ||
} | ||
|
||
module.exports = auth; | ||
module.exports = auth |
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
const Mock = require("mockjs"); | ||
const Mock = require('mockjs') | ||
|
||
var data = Mock.mock({ | ||
const data = Mock.mock({ | ||
// 属性 list 的值是一个数组,其中含有 1 到 10 个元素 | ||
"list|100": [ | ||
'list|100': [ | ||
{ | ||
// 属性 id 是一个自增数,起始值为 1,每次增 1 | ||
"id|+1": 1, | ||
name: "@first", | ||
"age|18-28": 25, | ||
"staff|1": ["前端", "后端", "测试", "运维", "产品", "设计"], | ||
}, | ||
], | ||
}); | ||
'id|+1': 1, | ||
name: '@first', | ||
'age|18-28': 25, | ||
'staff|1': ['前端', '后端', '测试', '运维', '产品', '设计'] | ||
} | ||
] | ||
}) | ||
|
||
module.exports = { | ||
data, | ||
}; | ||
data | ||
} |
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
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const express = require('express') | ||
const router = express.Router() | ||
|
||
// 获取用户信息 | ||
router.get('/', async (req, res) => { | ||
const html = ` | ||
const html = ` | ||
<div> | ||
<h1>数据库服务</h1> | ||
</div> | ||
` | ||
res.send(html); | ||
}); | ||
res.send(html) | ||
}) | ||
|
||
module.exports = router; | ||
module.exports = router |
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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
const { connection } = require("../../db/mysql"); | ||
const { data } = require("../../mock/user"); | ||
console.log(data, 'list'); | ||
const { list } = data; | ||
const sql = 'insert into emp(name, age, staff, create_time) values (?,?,?, now())'; | ||
const { connection } = require('../../db/mysql') | ||
const { data } = require('../../mock/user') | ||
const sql = 'insert into emp(name, age, staff, create_time) values (?,?,?, now())' | ||
|
||
function insetIntoUser(obj) { | ||
function insetIntoUser (obj) { | ||
obj.list.forEach((item) => { | ||
const { name, age, staff } = item; | ||
const { name, age, staff } = item | ||
connection.query(sql, [name, age, staff], (err, result) => { | ||
if (err) { | ||
console.log(err, 'err'); | ||
return; | ||
console.log(err, 'err') | ||
return | ||
} | ||
console.log('写入成功'); | ||
console.log('写入成功') | ||
}) | ||
}); | ||
}) | ||
} | ||
|
||
insetIntoUser(data); | ||
insetIntoUser(data) |
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
const COS = require('cos-nodejs-sdk-v5'); | ||
const dotenv = require("dotenv"); | ||
dotenv.config(); | ||
const {SECRET_ID, SECRET_KEY} = process.env; | ||
const COS = require('cos-nodejs-sdk-v5') | ||
const dotenv = require('dotenv') | ||
dotenv.config() | ||
const { SECRET_ID, SECRET_KEY } = process.env | ||
|
||
dotenv.config(); | ||
dotenv.config() | ||
const cos = new COS({ | ||
SecretId: SECRET_ID, | ||
SecretKey: SECRET_KEY, | ||
SecretKey: SECRET_KEY | ||
}) | ||
|
||
module.exports = cos | ||
module.exports = cos |
Oops, something went wrong.