forked from VinokurovVE/tests
EMS: move DB connection to env
This commit is contained in:
8
ems/package-lock.json
generated
8
ems/package-lock.json
generated
@ -13,7 +13,7 @@
|
|||||||
"axios": "^1.7.4",
|
"axios": "^1.7.4",
|
||||||
"body-parser": "^1.20.2",
|
"body-parser": "^1.20.2",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.7",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"express-validator": "^7.2.0",
|
"express-validator": "^7.2.0",
|
||||||
"ioredis": "^5.4.1",
|
"ioredis": "^5.4.1",
|
||||||
@ -1525,9 +1525,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/dotenv": {
|
"node_modules/dotenv": {
|
||||||
"version": "16.4.5",
|
"version": "16.4.7",
|
||||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz",
|
||||||
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
|
"integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
},
|
},
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
"axios": "^1.7.4",
|
"axios": "^1.7.4",
|
||||||
"body-parser": "^1.20.2",
|
"body-parser": "^1.20.2",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.7",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"express-validator": "^7.2.0",
|
"express-validator": "^7.2.0",
|
||||||
"ioredis": "^5.4.1",
|
"ioredis": "^5.4.1",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import express, { Request, Response } from 'express';
|
import express, { Request, Response } from 'express';
|
||||||
import { tediousQuery } from '../../utils/tedious';
|
import { tediousQuery } from '../../utils/tedious';
|
||||||
import { GeneralDB } from '../../constants/db';
|
import { GeneralDB, GisDB } from '../../constants/db';
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
router.get('/regions/all', async (req: Request, res: Response) => {
|
router.get('/regions/all', async (req: Request, res: Response) => {
|
||||||
@ -120,7 +120,7 @@ router.get('/objects/list', async (req: Request, res: Response) => {
|
|||||||
type_id,
|
type_id,
|
||||||
CAST(LEFT(caption_params, CHARINDEX(',', caption_params + ',') - 1) AS VARCHAR(255)), -- Explicitly casting to VARCHAR
|
CAST(LEFT(caption_params, CHARINDEX(',', caption_params + ',') - 1) AS VARCHAR(255)), -- Explicitly casting to VARCHAR
|
||||||
STUFF(caption_params, 1, CHARINDEX(',', caption_params + ','), '')
|
STUFF(caption_params, 1, CHARINDEX(',', caption_params + ','), '')
|
||||||
FROM New_Gis..caption_params
|
FROM ${GisDB}..caption_params
|
||||||
WHERE city_id = -1 AND user_id = -1
|
WHERE city_id = -1 AND user_id = -1
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
@ -143,7 +143,7 @@ router.get('/objects/list', async (req: Request, res: Response) => {
|
|||||||
FROM ${GeneralDB}..vObjects o
|
FROM ${GeneralDB}..vObjects o
|
||||||
JOIN cte_split c ON o.type = c.type_id
|
JOIN cte_split c ON o.type = c.type_id
|
||||||
JOIN ${GeneralDB}..tParameters p ON p.id = split_value
|
JOIN ${GeneralDB}..tParameters p ON p.id = split_value
|
||||||
JOIN ${GeneralDB}..tValues v
|
LEFT JOIN ${GeneralDB}..tValues v
|
||||||
ON
|
ON
|
||||||
v.id_param = split_value
|
v.id_param = split_value
|
||||||
AND v.id_object = o.object_id
|
AND v.id_object = o.object_id
|
||||||
|
@ -6,6 +6,7 @@ import gisRouter from './api/gis'
|
|||||||
import nodesRouter from './api/nodes'
|
import nodesRouter from './api/nodes'
|
||||||
import tilesRouter from './api/tiles'
|
import tilesRouter from './api/tiles'
|
||||||
import staticRouter from './api/static'
|
import staticRouter from './api/static'
|
||||||
|
import 'dotenv/config'
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
const PORT = process.env.EMS_PORT || 5000
|
const PORT = process.env.EMS_PORT || 5000
|
||||||
|
@ -1,25 +1,30 @@
|
|||||||
import { Connection, ConnectionConfiguration, Request } from "tedious";
|
import { Connection, ConnectionConfiguration, Request } from "tedious";
|
||||||
|
import 'dotenv/config'
|
||||||
|
|
||||||
|
const MSSQL_HOST = process.env.MSSQL_HOST || 'localhost'
|
||||||
|
const MSSQL_LOGIN = process.env.MSSQL_LOGIN || 'sa'
|
||||||
|
const MSSQL_PASSWORD = process.env.MSSQL_PASSWORD || ''
|
||||||
|
const MSSQL_DB = process.env.MSSQL_DB || 'nGeneral'
|
||||||
|
const MSSQL_PORT = Number(process.env.MSSQL_PORT) || 1433
|
||||||
|
|
||||||
const tediousConfig: ConnectionConfiguration = {
|
const tediousConfig: ConnectionConfiguration = {
|
||||||
server: 'localhost',
|
server: MSSQL_HOST,
|
||||||
options: {
|
options: {
|
||||||
trustServerCertificate: true,
|
trustServerCertificate: true,
|
||||||
port: 1433,
|
port: MSSQL_PORT,
|
||||||
database: 'nGeneral'
|
database: MSSQL_DB
|
||||||
},
|
},
|
||||||
authentication: {
|
authentication: {
|
||||||
type: 'default',
|
type: 'default',
|
||||||
options: {
|
options: {
|
||||||
userName: 'SA',
|
userName: MSSQL_LOGIN,
|
||||||
password: 'oMhthmsvbYHc'
|
password: MSSQL_PASSWORD
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tediousQuery(query: string) {
|
export function tediousQuery(query: string) {
|
||||||
// Read all rows from table
|
// Read all rows from table
|
||||||
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const connection = new Connection(tediousConfig)
|
const connection = new Connection(tediousConfig)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user