oneuptime/accounts/index.ts

92 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-01-26 14:03:42 +00:00
process.on('exit', () => {
2021-07-08 19:33:17 +00:00
// eslint-disable-next-line no-console
2021-01-26 14:03:42 +00:00
console.log('Shutting Shutdown');
});
process.on('unhandledRejection', err => {
2021-07-08 19:33:17 +00:00
// eslint-disable-next-line no-console
2021-01-26 14:03:42 +00:00
console.error('Unhandled rejection in process occurred');
2021-07-08 19:33:17 +00:00
// eslint-disable-next-line no-console
2021-01-26 14:03:42 +00:00
console.error(err);
});
process.on('uncaughtException', err => {
2021-07-08 19:33:17 +00:00
// eslint-disable-next-line no-console
2021-01-26 14:03:42 +00:00
console.error('Uncaught exception in process occurred');
2021-07-08 19:33:17 +00:00
// eslint-disable-next-line no-console
2021-01-26 14:03:42 +00:00
console.error(err);
});
2022-02-25 13:22:20 +00:00
import express from 'express'
import path from 'path'
2019-08-02 12:56:16 +00:00
const app = express();
2022-02-25 13:22:20 +00:00
import compression from 'compression'
2019-08-29 08:10:51 +00:00
app.use(compression());
2020-04-29 14:28:39 +00:00
app.get(['/env.js', '/accounts/env.js'], function(req, res) {
2020-03-23 20:59:33 +00:00
const env = {
REACT_APP_IS_SAAS_SERVICE: process.env.IS_SAAS_SERVICE,
2020-04-29 09:30:13 +00:00
REACT_APP_DISABLE_SIGNUP: process.env.DISABLE_SIGNUP,
2020-03-23 20:59:33 +00:00
REACT_APP_HOST: req.host,
REACT_APP_STRIPE_PUBLIC_KEY: process.env.STRIPE_PUBLIC_KEY,
REACT_APP_AMPLITUDE_PUBLIC_KEY: process.env.AMPLITUDE_PUBLIC_KEY,
REACT_APP_VERSION:
process.env.npm_package_version || process.env.REACT_APP_VERSION,
2020-03-23 20:59:33 +00:00
};
2020-03-22 14:22:56 +00:00
res.contentType('application/javascript');
res.send('window._env = ' + JSON.stringify(env));
2019-09-09 13:30:52 +00:00
});
app.use(express.static(path.join(__dirname, 'build')));
2021-12-27 12:06:39 +00:00
app.use(
'/accounts/static/js',
express.static(path.join(__dirname, 'build', 'static', 'js'))
2021-12-27 12:06:39 +00:00
);
// app.use(
// /^\/accounts\/static\/js\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])\.(.+)\.chunk\.js$/,
// function(req, res, next) {
// let baseUrls = req.baseUrl;
// baseUrls = baseUrls.split('/');
// const fileName = baseUrls[baseUrls.length - 1];
// if (fileName) {
// res.sendFile(
// path.join(__dirname, 'build', 'static', 'js', fileName)
// );
// } else {
// return next();
// }
// }
// );
// app.use(/^\/accounts\/static\/js\/main\.(.+)\.chunk\.js$/, function(
// req,
// res,
// next
// ) {
// let baseUrls = req.baseUrl;
// baseUrls = baseUrls.split('/');
// const fileName = baseUrls[baseUrls.length - 1];
// if (fileName) {
// res.sendFile(path.join(__dirname, 'build', 'static', 'js', fileName));
// } else {
// return next();
// }
// });
2021-12-27 10:04:03 +00:00
app.use('/accounts', express.static(path.join(__dirname, 'build')));
2020-04-29 14:28:39 +00:00
app.get('/*', function(req, res) {
2020-02-27 11:15:46 +00:00
res.sendFile(path.join(__dirname, 'build', 'index.html'));
2019-08-02 12:56:16 +00:00
});
2020-03-18 21:29:35 +00:00
const PORT = process.env.PORT || 3003;
2021-07-08 19:33:17 +00:00
// eslint-disable-next-line no-console
2020-02-27 11:15:46 +00:00
console.log(`This project is running on port ${PORT}`);
app.listen(PORT);