Skip to content

Commit

Permalink
fix: fix config options
Browse files Browse the repository at this point in the history
  • Loading branch information
DCsunset committed Mar 21, 2023
1 parent ec37448 commit a547c84
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ RUN apk --no-cache add nodejs npm && \
npm i -g task.json-server

ENV NODE_ENV=production
ENV TJ_DATA_PATH=/data

VOLUME ["/data"]

CMD ["tj-server"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "tsx ./src/server.ts",
"build": "rm -rf dist && tsc -p ./tsconfig.build.json",
"start": "NODE_ENV=production node ./dist/server.js",
"test": "jest"
"test": "TJ_DATA_PATH=./tests jest"
},
"bin": {
"tj-server": "./dist/server.js"
Expand Down
20 changes: 9 additions & 11 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>
*/

import * as path from "path";

export const isProd = process.env.NODE_ENV === 'production';

export const config = {
host: process.env.ADDR || (isProd ? "0.0.0.0" : "localhost"),
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
rootPath: process.env.ROOT_PATH
|| (isProd ? "/data" : path.join(__dirname, "../../tests")),
password: process.env.PASSWORD || "admin",
host: process.env.TJ_ADDR || (isProd ? "0.0.0.0" : "localhost"),
port: process.env.TJ_PORT ? parseInt(process.env.TJ_PORT) : 3000,
dataPath: process.env.TJ_DATA_PATH || "./data",
// password for login
password: process.env.TJ_PASSWORD || "admin",
jwt: {
secret: process.env.SECRET || "secret",
expiresIn: "90d",
},
maxClients: process.env.MAX_CLIENTS ? parseInt(process.env.MAX_CLIENTS) : 3
// secret for signing jwt
secret: process.env.TJ_JWT_SECRET || "secret",
expiresIn: process.env.TJ_JWT_EXPIRES_IN || "60d",
}
};
10 changes: 5 additions & 5 deletions src/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import fs from "fs";
import path from "path";

export function saveData(taskJson: string) {
const dataPath = path.join(config.rootPath, "task.json");
const dataPath = path.join(config.dataPath, "task.json");

if (!fs.existsSync(config.rootPath)) {
fs.mkdirSync(config.rootPath);
if (!fs.existsSync(config.dataPath)) {
fs.mkdirSync(config.dataPath);
}

fs.writeFileSync(
Expand All @@ -34,7 +34,7 @@ export function saveData(taskJson: string) {
}

export function loadData() {
const dataPath = path.join(config.rootPath, "task.json");
const dataPath = path.join(config.dataPath, "task.json");

if (!fs.existsSync(dataPath)) {
return undefined;
Expand All @@ -45,7 +45,7 @@ export function loadData() {
}

export function deleteData() {
const dataPath = path.join(config.rootPath, "task.json");
const dataPath = path.join(config.dataPath, "task.json");
if (fs.existsSync(dataPath)) {
fs.unlinkSync(dataPath);
}
Expand Down

0 comments on commit a547c84

Please sign in to comment.