-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
2 changed files
with
40 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
})(); |