Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.git
.gitignore
node_modules
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
*.log
desktop/dist
desktop/node_modules
.idea
README.md
img

**/.DS_Store
**/.git
**/.gitignore
**/.vscode
**/.idea

**/node_modules
**/npm-debug.log
**/yarn-error.log
**/package-lock.json

**/dist
**/build
**/coverage

**/.env
**/.env.local
**/.env.*.local


**/README.md
**/CHANGELOG.md
**/logs
**/*.log
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Build stage
FROM node:20-alpine as builder

WORKDIR /app

RUN apk add --no-cache git

# Copy source code
COPY . .

RUN corepack enable


# Install dependencies
RUN yarn install

# Build application
RUN yarn web-build

# Production stage
FROM node:20-alpine

WORKDIR /app


RUN apk add --no-cache git

# Create data directory
RUN mkdir -p /app/data

# Copy necessary files
COPY --from=builder /app/package.json /app/yarn.lock /app/.yarnrc.yml ./
COPY --from=builder /app/backEnd ./backEnd
COPY --from=builder /app/frontEnd/dist ./frontEnd/dist
COPY --from=builder /app/core ./core

RUN corepack enable
# Install production dependencies
RUN yarn workspace back-end install

# Set data directory permissions
RUN chown -R node:node /app/data

# Switch to non-root user
USER node

# Expose port
EXPOSE 9002

# Start application
CMD ["yarn", "web-start"]
15 changes: 7 additions & 8 deletions backEnd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,31 @@
"@types/supertest": "^2.0.12",
"@types/type-is": "^1.6.3",
"jest": "^28.1.1",
"livemock-core": "workspace:*",
"mockserver-client": "^5.13.2",
"mockserver-node": "^5.13.2",
"mockttp": "^3.1.0",
"nodemon": "^2.0.16",
"prettier": "2.8.7",
"supertest": "^6.3.3",
"ts-jest": "^28.0.5",
"ts-node": "^10.7.0",
"tsconfig-paths": "^4.2.0"
"ts-jest": "^28.0.5"
},
"dependencies": {
"@types/micromatch": "^4.0.7",
"body-parser": "^1.20.0",
"express": "4.18.1",
"form-data": "^4.0.0",
"http-proxy": "^1.18.1",
"livemock-core": "workspace:*",
"lodash": "^4.17.21",
"lokijs": "git+https://github.com/alinGmail/LokiJS.git#94aa10183ab444d3f11d59a19314db39d3cb6ef3",
"lokijs": "git+https://github.com/alinGmail/LokiJS.git#265bbcaeafccac11ab556599e478380cd07ffca7",
"micromatch": "^4.0.5",
"mockjs": "^1.1.0",
"nedb": "^1.8.0",
"node-mocks-http": "^1.12.2",
"requires-port": "^1.0.0",
"socket.io": "^4.6.2",
"ts-node": "^10.7.0",
"tsconfig-paths": "^4.2.0",
"livemock-core": "workspace:*",
"supertest": "^6.3.3",
"type-is": "^1.6.18"
}
}
}
50 changes: 50 additions & 0 deletions backEnd/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import path from 'path';
import fs from 'fs';

interface Config {
database: {
path: string;
}
}

// Default configuration
const defaultConfig: Config = {
database: {
path: 'db'
}
};

// Ensure directory exists
function ensureDirectoryExists(dirPath: string) {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
}

// Check if running in test environment
function isTestEnvironment(): boolean {
return process.env.NODE_ENV === 'test' ||
process.env.JEST_WORKER_ID !== undefined ||
process.argv.some(arg => arg.includes('jest'));
}

// Load configuration from environment variables
export function loadConfig(): Config {
const config = {
database: {
path: process.env.LIVEMOCK_DB_PATH || defaultConfig.database.path
}
};

// Only create directory in non-test environment
if (!isTestEnvironment()) {
ensureDirectoryExists(config.database.path);
}

return config;
}

// Get current configuration
export function getConfig(): Config {
return loadConfig();
}
38 changes: 38 additions & 0 deletions backEnd/src/controller/logController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
DeleteAllRequestLogsPathParam,
DeleteAllRequestLogsReqBody,
DeleteAllRequestLogsReqQuery,
GetLogDetailPathParam,
GetLogDetailReqBody,
GetLogDetailReqQuery,
GetLogDetailResponse,
ListLogPathParam,
ListLogReqBody,
ListLogReqQuery,
Expand Down Expand Up @@ -78,6 +82,7 @@ export async function getLogRouter(path: string): Promise<express.Router> {
}
);


/**
* list the log view
*/
Expand All @@ -104,6 +109,39 @@ export async function getLogRouter(path: string): Promise<express.Router> {
}
);


/**
* get log item
*/
router.get(
`/detail/:logId`,
async (
req: Request<
GetLogDetailPathParam,
GetLogDetailResponse,
GetLogDetailReqBody,
GetLogDetailReqQuery
>,
res: Response<GetLogDetailResponse>
) => {
addCross(res);
const logId = parseInt(req.params.logId);
if (!logId) {
throw new ServerError(400, "log id not exist!");
}
const projectId = req.query.projectId;
const collection = await getLogCollection(projectId, path);

const logItem = collection.findOne({ id: logId });
if (logItem === null) {
throw new ServerError(500, "log item not found!");
}
res.json({
logItem,
});
}
);

/**
* get the log view logs
*/
Expand Down
20 changes: 12 additions & 8 deletions backEnd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getSystemCollection } from "./db/dbManager";
import { sysEventEmitter } from "./common/eventEmitters";
import { SystemEvent } from "livemock-core/struct/events/systemEvent";
import { addWsEventListeners } from "./common/eventListener";
import { getConfig } from "./config/config";

const { Server } = require("socket.io");

Expand All @@ -22,8 +23,11 @@ const io = new Server(http, {
});
export const systemVersion = 801;

const config = getConfig();
const dbPath = config.database.path;

sysEventEmitter.on(SystemEvent.START, async () => {
const systemCollection = await getSystemCollection("db");
const systemCollection = await getSystemCollection(dbPath);
const systemConfig = systemCollection.findOne({});
if (systemConfig) {
} else {
Expand All @@ -39,17 +43,17 @@ addWsEventListeners();
sysEventEmitter.listeners(SystemEvent.START).map((listener) => listener())
);

server.use("/project", await getProjectRouter("db"));
server.use("/expectation", getExpectationRouter("db"));
server.use("/matcher", getMatcherRouter("db"));
server.use("/action", await getActionRouter("db"));
server.use("/logFilter", await getLogFilterRouter("db"));
server.use("/log", await getLogRouter("db"));
server.use("/project", await getProjectRouter(dbPath));
server.use("/expectation", getExpectationRouter(dbPath));
server.use("/matcher", getMatcherRouter(dbPath));
server.use("/action", await getActionRouter(dbPath));
server.use("/logFilter", await getLogFilterRouter(dbPath));
server.use("/log", await getLogRouter(dbPath));
server.use("/dashboard", express.static("../frontEnd/dist"));
server.all("/", (req, res) => {
res.redirect("/dashboard");
});
await addLogListener(io, "db");
await addLogListener(io, dbPath);

server.use(CustomErrorMiddleware);
http.listen(9002, () => {
Expand Down
2 changes: 2 additions & 0 deletions core/struct/events/desktopEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export enum ActionEvents {
export enum LogViewEvents{
ListLogView="ListLogView",
ListLogViewLogs="ListLogViewLogs",
GetLogDetail="GetLogDetail",
DeleteAllRequestLogs="DeleteAllRequestLogs",
OnLogAdd="OnLogViewLogAdd",
OnLogUpdate="OnLogViewLogUpdate",
Expand All @@ -54,4 +55,5 @@ export enum LogFilterEvents{

export enum SystemEvents{
OpenAboutWindow = "OpenAboutWindow",
OpenNewWindow = "OpenNewWindow",
}
Loading