Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
process.on('SIGINT', function () {
process.exit(0);
});
// web service
var app = express();
app.configure(function(){
app.use(express.static(__dirname + '/public'))
app.use(app.router);
app.set('rasterizerService', new RasterizerService(config.rasterizer).startService());
app.set('fileCleanerService', new FileCleanerService(config.cache.lifetime));
});
app.configure('development', function() {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
require('./routes')(app, config.server.useCors);
app.listen(config.server.port, config.server.host);
console.log('Express server listening on ' + config.server.host + ':' + config.server.port);
function invalidateCache (req, res) {
if (config.server.useOutputCache) {
if (req.query.tag && req.query.key) { // clear cache pages for specific query tag
if (req.query.key !== config.server.invalidateCacheKey) {
console.error('Invalid cache invalidation key')
apiStatus(res, 'Invalid cache invalidation key', 500)
return
}
console.log(`Clear cache request for [${req.query.tag}]`)
let tags = []
if (req.query.tag === '*') {
tags = config.server.availableCacheTags
} else {
tags = req.query.tag.split(',')
}
const subPromises = []
tags.forEach(tag => {
if (config.server.availableCacheTags.indexOf(tag) >= 0 || config.server.availableCacheTags.find(t => {
return tag.indexOf(t) === 0
})) {
subPromises.push(cache.invalidate(tag).then(() => {
console.log(`Tags invalidated successfully for [${tag}]`)
}))
} else {
console.error(`Invalid tag name ${tag}`)
}
})
Promise.all(subPromises).then(r => {
debug('Log config');
if (config.isProduction) {
logger.info('App config', { data: config, tags: 'server' });
}
// Handler for uncaught exceptions
debug('Handler for uncaught exceptions');
handleUncaughtException();
// Pass config to whatever needs it
const usersClientValidations = require('../common/helpers/usersClientValidations');
usersClientValidations.setClientValidationsConfig(config);
// Start server
const port = normalizePort(config.server.port);
debug('Require app');
const app = require('./app');
debug('Start server');
const server = app.listen(port)
.on('error', onError)
.on('listening', onListening);
// Handle uncaught exceptions
// Consider enhancements at: https://coderwall.com/p/4yis4w/node-js-uncaught-exceptions
function handleUncaughtException() {
process.on('uncaughtException', (error) => {
debug('Uncaught exception');
console.error('\n\n=== uncaught exception ================='); // eslint-disable-line no-console
console.error(error.message); // eslint-disable-line no-console
import webpack from 'webpack';
import merge from 'webpack-merge';
import base from './webpack.base.config';
import VueSSRPlugin from 'vue-ssr-webpack-plugin';
// when output cache is enabled generate cache version key
import config from 'config';
import fs from 'fs';
import path from 'path';
import uuid from 'uuid/v4';
if (config.server.useOutputCache) {
fs.writeFileSync(
path.join(__dirname, 'cache-version.json'),
JSON.stringify(uuid())
);
}
export default merge(base, {
mode: 'development',
target: 'node',
entry: ['@babel/polyfill', './core/server-entry.ts'],
output: {
filename: 'server-bundle.js',
libraryTarget: 'commonjs2'
},
resolve: {
alias: {
case '*':
throw new Error('Characters &, ? and * are invalid for param folding-char!');
}
// special handling of no* by optimist module needed
if (value['save']) value['nosave'] = false;
// now write back all values into config object to overwrite defaults with cli params
config.noSave = value['nosave'];
config.noLogData = (value['log-data']===false); // due to special negated param
config.ui.foldingChar = value['folding-char'];
config.redis.useScan = value['use-scan'];
config.redis.readOnly = value['read-only'];
config.redis.scanCount = value['scan-count'];
config.redis.rootPattern = value['root-pattern'];
config.redis.defaultLabel = value['redis-label'];
config.server.address = value['address'];
config.server.port = value['port'];
config.server.urlPrefix = value['url-prefix'];
config.server.trustProxy = value['trust-proxy'];
config.server.httpAuth.username = value['http-auth-username'];
config.server.httpAuth.password = value['http-auth-password'];
config.server.httpAuth.passwordHash = value['http-auth-password-hash'];
})
.argv;
key: fs.readFileSync(config.https_server.private_key),
cert: fs.readFileSync(config.https_server.public_key)
};
} else {
// use http module by default
var http = require('http');
}
// register koop providers
koop.register(socrata);
koop.register(ckan);
koop.register(github);
koop.register(gist);
koop.register(agol);
app.set('port', process.env.PORT || config.server.port || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(cors()); // add CORS support (recommended)
app.use(koop); // add koop middleware
app.get('/status', function (req, res) {
res.json(koop.status);
});
app.get('/', function (req, res) {
res.render('index', { status: koop.status });
});
if (config.https_server) {
server = https.createServer(options, app);
return products.map(product => {
product = Object.assign({}, preConfigureProduct({ product, populateRequestCacheTags: config.server.useOutputCacheTagging }))
const configuredProductVariant = configureProductAsync({rootState, state: {current_configuration: {}}}, {product, configuration: filters, selectDefaultVariant: false, fallbackToDefaultWhenNoAvailable: true, setProductErorrs: false})
return Object.assign(product, omit(configuredProductVariant, ['visibility']))
})
},
*
* Fightly - Web Game Engine
* http://fightly.com
*
**********************************************************************/
var config = require('config');
var network = require('./src/network/com-manager'),
GameEngine = require('./src/game-engine');
var engine = new GameEngine(config),
server = new network.ComManager(engine);
engine.init();
server.listen(config.server.port);
const config = require("config");
config.server = config.server || {};
config.server.host = config.server.host || "0.0.0.0";
config.server.port = config.server.port || 3000;
config.server.headers = config.server.headers || {};
config.server.headers["X-Frame-Options"] =
typeof config.server.headers["X-Frame-Options"] === "undefined"
? "sameorigin"
: config.server.headers["X-Frame-Options"];