Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nuxt-backend-helper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王曜嵚 Wang Yaoqin
nuxt-backend-helper
Commits
b649bc12
Commit
b649bc12
authored
May 06, 2024
by
王曜嵚 Wang Yaoqin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev: 环境变量
parent
75221ace
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
49 additions
and
46 deletions
+49
-46
ProjectV1.vue
components/ProjectV1.vue
+1
-1
ProjectV2.vue
components/ProjectV2.vue
+1
-1
nuxt.config.ts
nuxt.config.ts
+10
-0
downloadWeApp.post.ts
server/api/devops/v2/downloadWeApp.post.ts
+1
-1
login.post.ts
server/api/user/login.post.ts
+1
-1
docker.ts
server/utils/docker.ts
+2
-17
environment.d.ts
server/utils/environment.d.ts
+13
-9
index.ts
server/utils/index.ts
+1
-1
postgres.ts
server/utils/postgres.ts
+13
-9
server.ts
server/utils/server.ts
+6
-6
No files found.
components/ProjectV1.vue
View file @
b649bc12
...
@@ -112,7 +112,7 @@ async function handleInstall() {
...
@@ -112,7 +112,7 @@ async function handleInstall() {
execute
()
execute
()
}
}
function
getTip
(
status
:
string
)
{
function
getTip
(
status
:
string
)
{
const
HOST
=
process
.
env
.
NODE_ENV
===
'production'
?
'192.168.0.4'
:
(
process
.
env
.
DEVHOST
||
'192.168.0.190'
)
const
HOST
=
useRuntimeConfig
().
public
.
dockerHost
const
port
=
useUserStore
().
port
const
port
=
useUserStore
().
port
const
map
=
new
Map
([
const
map
=
new
Map
([
[
'null'
,
'请点击右侧按钮完成项目初始化'
],
[
'null'
,
'请点击右侧按钮完成项目初始化'
],
...
...
components/ProjectV2.vue
View file @
b649bc12
...
@@ -141,7 +141,7 @@ async function handleInstall() {
...
@@ -141,7 +141,7 @@ async function handleInstall() {
}
}
function
getTip
(
status
:
string
)
{
function
getTip
(
status
:
string
)
{
const
HOST
=
process
.
env
.
NODE_ENV
===
'production'
?
'192.168.0.4'
:
(
process
.
env
.
DEVHOST
||
'192.168.0.190'
)
const
HOST
=
useRuntimeConfig
().
public
.
dockerHost
const
port
=
useUserStore
().
port
const
port
=
useUserStore
().
port
const
map
=
new
Map
([
const
map
=
new
Map
([
[
'null'
,
'请点击右侧按钮完成项目初始化'
],
[
'null'
,
'请点击右侧按钮完成项目初始化'
],
...
...
nuxt.config.ts
View file @
b649bc12
...
@@ -8,5 +8,15 @@ export default defineNuxtConfig({
...
@@ -8,5 +8,15 @@ export default defineNuxtConfig({
experimental
:
{
experimental
:
{
websocket
:
true
websocket
:
true
}
}
},
runtimeConfig
:
{
pgUser
:
''
,
pgPort
:
''
,
pgHost
:
''
,
pgPassword
:
''
,
pgDatabase
:
''
,
public
:
{
dockerHost
:
''
}
}
}
})
})
server/api/devops/v2/downloadWeApp.post.ts
View file @
b649bc12
...
@@ -12,7 +12,7 @@ export default defineEventHandler(async (event) => {
...
@@ -12,7 +12,7 @@ export default defineEventHandler(async (event) => {
LogUtil
.
print
(
username
,
`[progress] [[1;34mInfo[m] 打包微信小程序zip \n`
)
LogUtil
.
print
(
username
,
`[progress] [[1;34mInfo[m] 打包微信小程序zip \n`
)
await
docker
.
execContainerCommand
({
container
,
cmd
:
'rm -f weapp.zip'
,
dir
:
'/var/logwire-backend/build-output/backend'
})
await
docker
.
execContainerCommand
({
container
,
cmd
:
'rm -f weapp.zip'
,
dir
:
'/var/logwire-backend/build-output/backend'
})
await
docker
.
execContainerCommand
({
container
,
cmd
:
`zip -q -r weapp.zip miniapp/main/dist miniapp/main/src/pages miniapp/main/src/app.config.ts`
,
dir
:
'/var/logwire-backend/build-output/backend'
})
await
docker
.
execContainerCommand
({
container
,
cmd
:
`zip -q -r weapp.zip miniapp/main/dist miniapp/main/src/pages miniapp/main/src/app.config.ts`
,
dir
:
'/var/logwire-backend/build-output/backend'
})
LogUtil
.
print
(
username
,
`[progress] [[1;34mInfo[m] 打包结束,访问 <a target="_blank" href="http://
192.168.0.4:
${
port
}
/download/backend/">http://192.168.0.4
:
${
port
}
/download/backend/</a> 下载 webapp.zip 文件 \n`
)
LogUtil
.
print
(
username
,
`[progress] [[1;34mInfo[m] 打包结束,访问 <a target="_blank" href="http://
${
HOST
}
:
${
port
}
/download/backend/">http://
${
HOST
}
:
${
port
}
/download/backend/</a> 下载 webapp.zip 文件 \n`
)
}
else
{
}
else
{
throw
new
Error
(
'没有创建容器,请先初始化容器'
)
throw
new
Error
(
'没有创建容器,请先初始化容器'
)
}
}
...
...
server/api/user/login.post.ts
View file @
b649bc12
...
@@ -9,7 +9,7 @@ export default defineEventHandler(async (event) => {
...
@@ -9,7 +9,7 @@ export default defineEventHandler(async (event) => {
let
user
=
await
getPgTableData
(
'user'
,
username
)
let
user
=
await
getPgTableData
(
'user'
,
username
)
if
(
!
user
)
{
if
(
!
user
)
{
const
port
=
await
getAvailableNodePort
(
HOST
)
const
port
=
await
getAvailableNodePort
(
useRuntimeConfig
().
public
.
dockerHost
)
await
insertPgTableData
(
'user'
,
username
)
await
insertPgTableData
(
'user'
,
username
)
await
setPgTableData
(
'user'
,
username
,
'port'
,
port
)
await
setPgTableData
(
'user'
,
username
,
'port'
,
port
)
user
=
await
getPgTableData
(
'user'
,
username
)
user
=
await
getPgTableData
(
'user'
,
username
)
...
...
server/utils/docker.ts
View file @
b649bc12
...
@@ -179,22 +179,7 @@ class Docker {
...
@@ -179,22 +179,7 @@ class Docker {
}
}
}
}
class
DevDocker
extends
Docker
{
constructor
(
username
:
string
)
{
super
(
'localhost'
,
username
)
}
}
class
ProductionDocker
extends
Docker
{
constructor
(
username
:
string
)
{
super
(
'192.168.0.4'
,
username
)
}
}
export
function
createDockerFactory
(
username
:
string
)
{
export
function
createDockerFactory
(
username
:
string
)
{
if
(
process
.
env
.
NODE_ENV
?.
trim
()
===
'production'
)
{
const
DOCKERHOST
=
useRuntimeConfig
().
public
.
dockerHost
return
new
ProductionDocker
(
username
)
return
new
Docker
(
process
.
env
.
NODE_ENV
===
'development'
?
'localhost'
:
DOCKERHOST
,
username
)
}
else
{
return
new
DevDocker
(
username
)
}
}
}
\ No newline at end of file
server/utils/environment.d.ts
View file @
b649bc12
declare
module
global
{
declare
module
'nuxt/schema'
{
namespace
NodeJS
{
interface
RuntimeConfig
{
interface
ProcessEnv
{
pgUser
:
string
DEVHOST
:
string
pgPort
:
string
NODE_ENV
:
string
pgHost
:
string
PGUSER
:
string
pgPassword
:
string
postgres
:
string
pgDatabase
:
string
}
}
}
}
interface
PublicRuntimeConfig
{
\ No newline at end of file
dockerHost
:
string
}
}
// 当增强类型时,确保始终导入/导出某些内容是很重要的
export
{}
\ No newline at end of file
server/utils/index.ts
View file @
b649bc12
import
fs
from
'fs'
import
fs
from
'fs'
export
const
HOST
=
process
.
env
.
NODE_ENV
===
'production'
?
'192.168.0.4'
:
(
process
.
env
.
DEVHOST
||
'192.168.0.190'
)
export
const
HOST
=
useRuntimeConfig
().
public
.
dockerHost
export
function
readJson
(
path
:
string
):
Record
<
string
,
any
>
{
export
function
readJson
(
path
:
string
):
Record
<
string
,
any
>
{
try
{
try
{
...
...
server/utils/postgres.ts
View file @
b649bc12
import
pg
from
'pg'
import
pg
from
'pg'
import
{
sendProjectStatus
}
from
'./log'
import
{
sendProjectStatus
}
from
'./log'
export
const
PgPort
=
process
.
env
.
NODE_ENV
?.
trim
()
===
'production'
?
25556
:
30001
const
config
=
useRuntimeConfig
()
export
const
PgHost
=
process
.
env
.
NODE_ENV
?.
trim
()
===
'production'
?
'192.168.0.4'
:
process
.
env
.
DEVHOST
export
const
PgPort
=
config
.
pgPort
export
const
PgHost
=
config
.
pgHost
let
pool
:
pg
.
Pool
=
new
pg
.
Pool
({
let
pool
:
pg
.
Pool
=
new
pg
.
Pool
({
host
:
PgHost
,
host
:
PgHost
,
port
:
PgPort
,
port
:
Number
(
PgPort
),
database
:
'backend_helper'
database
:
'backend_helper'
,
user
:
config
.
pgUser
,
password
:
config
.
pgPassword
})
})
export
async
function
createPgClient
(
payload
:
{
export
async
function
createPgClient
(
payload
:
{
...
@@ -18,11 +22,11 @@ export async function createPgClient (payload: {
...
@@ -18,11 +22,11 @@ export async function createPgClient (payload: {
port
?:
number
port
?:
number
})
{
})
{
let
client
=
new
pg
.
Client
({
let
client
=
new
pg
.
Client
({
user
:
payload
.
user
,
user
:
payload
.
user
||
config
.
pgUser
,
password
:
payload
.
password
,
password
:
payload
.
password
||
config
.
pgPassword
,
database
:
payload
.
database
,
database
:
payload
.
database
||
config
.
pgDatabase
,
host
:
payload
.
host
||
P
gHost
,
host
:
payload
.
host
||
config
.
p
gHost
,
port
:
payload
.
port
||
PgPort
port
:
payload
.
port
||
Number
(
config
.
pgPort
)
})
})
await
client
.
connect
()
await
client
.
connect
()
return
client
return
client
...
...
server/utils/server.ts
View file @
b649bc12
...
@@ -62,9 +62,9 @@ export async function copyAndCreateServerPropertiesV2InDocker (username: string)
...
@@ -62,9 +62,9 @@ export async function copyAndCreateServerPropertiesV2InDocker (username: string)
const
fn
=
(
f
:
(
obj
:
Record
<
string
,
any
>
)
=>
string
)
=>
f
(
userConfigs
!
)
||
f
(
userDefaultSetting
)
const
fn
=
(
f
:
(
obj
:
Record
<
string
,
any
>
)
=>
string
)
=>
f
(
userConfigs
!
)
||
f
(
userDefaultSetting
)
// postgres config
// postgres config
backendText
=
backendText
.
replace
(
/spring.datasource.url=
(
.*
?)\r?\n
/
,
`spring.datasource.url=jdbc:postgresql://
${
HOST
}
:
${
PgPort
}
/
${
username
}
\n`
)
backendText
=
backendText
.
replace
(
/spring.datasource.url=
(
.*
?)\r?\n
/
,
`spring.datasource.url=jdbc:postgresql://
${
PgHost
}
:
${
PgPort
}
/
${
username
}
\n`
)
backendText
=
backendText
.
replace
(
/spring.datasource.username=
(
.*
?)\r?\n
/
,
`spring.datasource.username=
${
process
.
env
.
PGUSER
}
\n`
)
backendText
=
backendText
.
replace
(
/spring.datasource.username=
(
.*
?)\r?\n
/
,
`spring.datasource.username=
${
useRuntimeConfig
().
pgUser
}
\n`
)
backendText
=
backendText
.
replace
(
/spring.datasource.password=
(
.*
?)\r?\n
/
,
`spring.datasource.password=
${
process
.
env
.
PGPASSWORD
}
\n`
)
backendText
=
backendText
.
replace
(
/spring.datasource.password=
(
.*
?)\r?\n
/
,
`spring.datasource.password=
${
useRuntimeConfig
().
pgPassword
}
\n`
)
// redis config
// redis config
backendText
=
backendText
.
replace
(
/spring.redis.host=
(
.*
?)\r?\n
/
,
`spring.redis.host=
${
HOST
}
\n`
)
backendText
=
backendText
.
replace
(
/spring.redis.host=
(
.*
?)\r?\n
/
,
`spring.redis.host=
${
HOST
}
\n`
)
...
@@ -125,9 +125,9 @@ export async function copyAndCreateServerPropertiesV1InDocker (username: string)
...
@@ -125,9 +125,9 @@ export async function copyAndCreateServerPropertiesV1InDocker (username: string)
const userConfigs = await getPgTableData('v1', username)
const userConfigs = await getPgTableData('v1', username)
// postgres config
// postgres config
backendText = backendText.replace(/spring.datasource.url=(.*?)\r?\n/, `
spring
.
datasource
.
url
=
jdbc
:
postgresql
:
//${
HOST
}:${PgPort}/${username + '_v1'}\n`)
backendText = backendText.replace(/spring.datasource.url=(.*?)\r?\n/, `
spring
.
datasource
.
url
=
jdbc
:
postgresql
:
//${
PgHost
}:${PgPort}/${username + '_v1'}\n`)
backendText
=
backendText
.
replace
(
/spring.datasource.username=
(
.*
?)\r?\n
/
,
`spring.datasource.username=
${
process
.
env
.
PGUSER
}
\n`
)
backendText
=
backendText
.
replace
(
/spring.datasource.username=
(
.*
?)\r?\n
/
,
`spring.datasource.username=
${
useRuntimeConfig
().
pgUser
}
\n`
)
backendText
=
backendText
.
replace
(
/spring.datasource.password=
(
.*
?)\r?\n
/
,
`spring.datasource.password=
${
process
.
env
.
PGPASSWORD
}
\n`
)
backendText
=
backendText
.
replace
(
/spring.datasource.password=
(
.*
?)\r?\n
/
,
`spring.datasource.password=
${
useRuntimeConfig
().
pgPassword
}
\n`
)
// redis config
// redis config
backendText
=
backendText
.
replace
(
/spring.redis.host=
(
.*
?)\r?\n
/
,
`spring.redis.host=
${
HOST
}
\n`
)
backendText
=
backendText
.
replace
(
/spring.redis.host=
(
.*
?)\r?\n
/
,
`spring.redis.host=
${
HOST
}
\n`
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment