forked from huridocs/uwazi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (44 loc) · 1.24 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* eslint-disable no-multi-str */
/* eslint-disable no-console */
const { access } = require('fs/promises');
/* eslint-disable global-require */
require('dotenv').config();
process.env.ROOT_PATH = process.env.ROOT_PATH || __dirname;
const { NODE_ENV } = process.env;
require.extensions['.scss'] = function scss() { };
require.extensions['.css'] = function css() { };
const fileExists = async filePath => {
try {
await access(filePath);
} catch (err) {
if (err?.code === 'ENOENT') {
return false;
}
if (err) {
throw err;
}
}
return true;
};
(async () => {
if (NODE_ENV === 'production') {
const productionBuildExists = await fileExists('./prod/app/server.js');
if (productionBuildExists) {
require('./prod/app/server.js');
} else {
try {
require('./app/server.js');
} catch (e) {
console.error(e);
console.error(
'\x1b[31m%s\x1b[0m',
"\nIf you are in a development environment you are probably trying to run a production uwazi without a production build, \
try 'yarn production-build' first"
);
}
}
} else {
require('@babel/register')({ extensions: ['.js', '.jsx', '.ts', '.tsx'] });
require('./app/server.js');
}
})();