Skip to content

Commit

Permalink
feat:welcome page is hidden in production environment
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanaslan committed Oct 26, 2021
1 parent 4b1cd93 commit 0d9d965
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import newrelic from './universal/tools/newrelic/newrelic';

import cookieParser from 'cookie-parser';
import {compose} from 'compose-middleware';
import { compose } from 'compose-middleware';
import compression from 'compression';
import path from 'path';
import Hiddie from 'hiddie';
Expand All @@ -18,9 +18,9 @@ import render from './render';
import registerControllers from './api/controllers';
import renderMultiple from './renderMultiple';

import {createCacheManagerInstance} from "./universal/core/cache/cacheUtils";
import { createCacheManagerInstance } from './universal/core/cache/cacheUtils';

import {HTTP_STATUS_CODES} from './universal/utils/constants';
import { HTTP_STATUS_CODES } from './universal/utils/constants';

import voltranConfig from '../voltran.config';

Expand All @@ -39,7 +39,7 @@ process.on('unhandledRejection', (reason, p) => {
process.exit(1);
});

process.on('message', (message) => {
process.on('message', message => {
handleProcessMessage(message);
});

Expand All @@ -52,48 +52,54 @@ Object.keys(fragmentManifest).forEach(index => {
fragments.push(name);
});

const handleProcessMessage = (message) => {
const handleProcessMessage = message => {
if (message?.msg?.action === 'deleteallcache') {
createCacheManagerInstance().removeAll();
} else if (message?.msg?.action === 'deletecache') {
createCacheManagerInstance().remove(message?.msg?.key);
}
}
};

const handleUrls = async (req, res, next) => {
if (req.url === '/' && req.method === 'GET') {
res.html(Welcome());
if (process.env.NODE_ENV === 'production') {
res
.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR)
.html('<h1>Aradığınız sayfa bulunamadı...</h1>');
} else {
res.html(Welcome());
}
} else if (req.url === '/metrics' && req.method === 'GET' && !enablePrometheus) {
res.setHeader('Content-Type', prom.register.contentType);
res.end(prom.register.metrics());
} else if (req.url === '/status' && req.method === 'GET') {
res.json({success: true, version: process.env.GO_PIPELINE_LABEL || '1.0.0', fragments});
res.json({ success: true, version: process.env.GO_PIPELINE_LABEL || '1.0.0', fragments });
} else if ((req.url === '/statusCheck' || req.url === '/statuscheck') && req.method === 'GET') {
res.json({success: true, version: process.env.GO_PIPELINE_LABEL || '1.0.0', fragments});
res.json({ success: true, version: process.env.GO_PIPELINE_LABEL || '1.0.0', fragments });
} else if (req.url === '/deleteallcache' && req.method === 'GET') {
process.send({
msg: {
action: 'deleteallcache',
action: 'deleteallcache'
},
options: {
forwardAllWorkers: true,
},
forwardAllWorkers: true
}
});
res.json({success: true});
res.json({ success: true });
} else if (req.path === '/deletecache' && req.method === 'GET') {
if (req?.query?.key) {
process.send({
msg: {
action: 'deletecache',
key: req?.query?.key,
key: req?.query?.key
},
options: {
forwardAllWorkers: true,
},
forwardAllWorkers: true
}
});
res.json({success: true});
res.json({ success: true });
} else {
res.json({success: false});
res.json({ success: false });
}
} else {
newrelic?.setTransactionName?.(req.path);
Expand Down Expand Up @@ -142,7 +148,7 @@ const locals = async (req, res, next) => {
req.url = xss(req.url);

if (req.headers['set-cookie']) {
req.headers['cookie'] = req.headers['cookie'] || req.headers['set-cookie']?.join();
req.headers.cookie = req.headers.cookie || req.headers['set-cookie']?.join();
delete req.headers['set-cookie'];
}

Expand Down

0 comments on commit 0d9d965

Please sign in to comment.