Skip to content

Commit 5b3db22

Browse files
committed
added conditional response for react build bundle and updated chokidar to listen only to .git directory changes
1 parent 533c155 commit 5b3db22

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

server.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@ const app = globalAPI;
1111
const log = console.log;
1212
var envConfigFilename = "env_config.json";
1313
var envConfigFilePath = path.join(__dirname, envConfigFilename);
14+
var isReactBundlePresent = false;
1415

15-
// DATABASE_FILE = path.join(__dirname, ".", DATABASE_FILE);
16+
try {
17+
fs.accessSync(path.join(__dirname, ".", "build"));
18+
isReactBundlePresent = true;
19+
} catch (err) {
20+
log("ERROR: ", err);
21+
isReactBundlePresent = false;
22+
}
1623

17-
app.use(express.static(path.join(__dirname, "build")));
24+
if (isReactBundlePresent) {
25+
app.use(express.static(path.join(__dirname, "build")));
26+
}
1827

1928
function getEnvData() {
2029
try {
@@ -107,7 +116,9 @@ log("INFO: Config file is present");
107116
log("INFO: Reading from config file " + envConfigFilePath);
108117

109118
app.get("/*", (req, res) => {
110-
res.sendFile(path.join(__dirname, "build", "index.html"));
119+
if (isReactBundlePresent) {
120+
res.sendFile(path.join(__dirname, "build", "index.html"));
121+
}
111122
});
112123

113124
globalAPI.listen(getEnvData().GITCONVEX_PORT || 9001, async (err) => {

utils/repoChangeListener.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const chokidar = require("chokidar");
2+
const path = require("path");
23
const { fetchRepoHandler } = require("../API/fetchRepoApi");
34
const { gitCommitLogToDb } = require("./sqliteDbAccess");
45

@@ -11,9 +12,9 @@ async function gitRepoListener() {
1112
if (repoPath) {
1213
repoPath.forEach((repo) => {
1314
chokidar
14-
.watch(repo, { interval: 1500, usePolling: true })
15-
.on("change", (path, stats) => {
16-
console.log("INFO: change noticed in ", path);
15+
.watch(path.join(repo, ".", ".git"))
16+
.on("change", (change, stats) => {
17+
console.log("INFO: change noticed in ", change);
1718
gitCommitLogToDb();
1819
});
1920
});

0 commit comments

Comments
 (0)