Skip to content

Commit

Permalink
Tweaks to server.js (#6375)
Browse files Browse the repository at this point in the history
* Clearer server.js

- Prevent hiding errors when trying to import non existent files
- New error message when trying to run production uwazi in a dev
  environment without the build

* Bump version
  • Loading branch information
daneryl authored Jan 18, 2024
1 parent f6399c4 commit 38a8ee9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uwazi",
"version": "1.149.0",
"version": "1.149.1",
"description": "Uwazi is a free, open-source solution for organising, analysing and publishing your documents.",
"keywords": [
"react"
Expand Down
48 changes: 39 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,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() {};
require.extensions['.scss'] = function scss() { };
require.extensions['.css'] = function css() { };

if (NODE_ENV === 'production') {
const fileExists = async filePath => {
try {
require('./app/server.js');
await access(filePath);
} catch (err) {
require('./prod/app/server.js');
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');
}
} else {
require('@babel/register')({ extensions: ['.js', '.jsx', '.ts', '.tsx'] });
require('./app/server.js');
}
})();

0 comments on commit 38a8ee9

Please sign in to comment.