create-nserve 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nserve",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "bin/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -8,6 +8,20 @@ const app = express()
8
8
  const run = async () => {
9
9
  try {
10
10
  LoadConfig(join(__dirname, 'config.yaml'))
11
+ app.use(express.json({ limit: '10mb' }))
12
+ app.use(express.urlencoded({ extended: true, limit: '10mb' }))
13
+ app.all(/.*/, function (req, res, next) {
14
+ const nowDate = new Date().toISOString()
15
+ console.info(`[INFO-${nowDate}-${req.method}] ${req.path}`)
16
+ res.header(
17
+ 'Access-Control-Allow-Headers',
18
+ 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
19
+ )
20
+ res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
21
+ res.header('X-Powered-By', ' 3.2.1')
22
+ res.header('Content-Type', 'application/json;charset=utf-8')
23
+ next()
24
+ })
11
25
  routers.length > 0 && app.use('/api', routers)
12
26
 
13
27
  // 健康检查
@@ -1,6 +1,6 @@
1
1
  import express from 'express'
2
2
  import routers from './handler/router'
3
- import emysql from '@dpapejs/emysql'
3
+ import emysql from '@aicblock/emysql'
4
4
  import { LoadConfig } from '@aicblock/nserve/lib/tools'
5
5
  import { join } from 'path'
6
6
  import models from '@/model'
@@ -17,15 +17,16 @@ const initDatabase = async () => {
17
17
  }
18
18
  try {
19
19
  global.mysql = new emysql({
20
- database,
21
- user,
22
- password,
23
- port,
24
- host,
20
+ connConfig: {
21
+ database,
22
+ user,
23
+ password,
24
+ port,
25
+ host
26
+ },
25
27
  log: 'debug'
26
28
  })
27
- const connection = await mysql.pool?.getConnection()
28
- connection?.release()
29
+ await mysql.init()
29
30
  models.length > 0 && (await mysql.table.create(models))
30
31
  } catch (error) {
31
32
  console.error('❌ 数据库连接失败:', error)
@@ -38,6 +39,20 @@ const run = async () => {
38
39
  try {
39
40
  LoadConfig(join(__dirname, 'config.yaml'))
40
41
  await initDatabase()
42
+ app.use(express.json({ limit: '10mb' }))
43
+ app.use(express.urlencoded({ extended: true, limit: '10mb' }))
44
+ app.all(/.*/, function (req, res, next) {
45
+ const nowDate = new Date().toISOString()
46
+ console.info(`[INFO-${nowDate}-${req.method}] ${req.path}`)
47
+ res.header(
48
+ 'Access-Control-Allow-Headers',
49
+ 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
50
+ )
51
+ res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
52
+ res.header('X-Powered-By', ' 3.2.1')
53
+ res.header('Content-Type', 'application/json;charset=utf-8')
54
+ next()
55
+ })
41
56
  routers.length > 0 && app.use('/api', routers)
42
57
 
43
58
  // 健康检查
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable no-var */
2
- import emysql from '@dpapejs/emysql'
3
- import eredis from '@/common/redis'
2
+ import emysql from '@aicblock/emysql'
4
3
  declare global {
5
4
  /**
6
5
  * mysql 服务