Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
/**
 * @todo only build client, import it using the output file location when it's ready...
 */
import { resolve as pathResolve } from 'path';
// global & builtin
import 'src/bootstrap/setup';
import 'src/bootstrap/polyfill/server';
// import './HACK'
// config
// external
import express from 'express';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
/**
 * @note - we removed this because we now will run it via nginx
 * https://gitlab.com/gitlab-org/gitlab-ce/issues/36469
 * https://codeburst.io/express-brotli-webpack-a60773e7ec6c
 */
// import expressStaticGzip from 'express-static-gzip'
// import shrinkRay from 'shrink-ray-current'
// import compression from 'compression'
// local
import { getConfigForEnv, appRootDir, resolveToRoot } from './aliased';
import { reactApplication } from './serverSideRender/reactApplication';
import security from './middleware/security';
import { tracingMiddleware } from './middleware/tracing';
import { routingMiddleware } from './middleware/routing';
import errorHandlers from './middleware/errorHandlers';
import { emptyMiddleware } from './middleware/empty';
import { fileMiddleware } from './middleware/fileMiddleware';
import { exportAccountMiddleware } from './middleware/exportAccountMiddleware';
import { pingMiddleware } from './middleware/pingMiddleware';
import { cacheMiddleware } from './caching';
import { loggerMiddleware, logger } from '@skava/logger';
import { userAgentMiddleware } from './middleware/userAgentMiddleware';
// @@pnp
if (process.env.LOG_TRACE_LOGS) {
    // require('fliplog').trackConsole()
}
// Create our express based server.
const app = express();
const pingEndpoint = express.Router();
const dynamic = {
    protection: emptyMiddleware,
};
pingEndpoint.get('/', pingMiddleware);
// @lint @todo thiis just uses a lot of middleware
// eslint-disable-next-line
function decorateApp(expressApp = app) {
    logger.debug('[appserver] decorateApp');
    // @note we use the get config because
    // 1. we build the node server with webpack still, unfortunately
    // 2. when we do that, we need to keep values dynamic & not replaced by env/define + shake/drop
    // const webPath = getConfigForEnv('bundles.client.webPath')
    const webPath = process.env.WEB_PATH;
    // @todo again
    const clientAssetUrl = resolveToRoot('dist/bundled/client');
    expressApp.use('client', express.static(clientAssetUrl));
    /**
     * @note - we have moved brotli to nginx
     * @todo https://codeburst.io/express-brotli-webpack-a60773e7ec6c
     */
    // expressApp.use(compression())
    // logger.debug('[server] using shrink-ray')
    expressApp.use(userAgentMiddleware);
    // logging middleware
    expressApp.use(tracingMiddleware);
    // @todo may need to disable this in dev
    expressApp.use(fileMiddleware);
    // Configure static serving of our "public" root http path static files.
    // Note: these will be served off the root (i.e. '/') of our application.
    // also this is super weird because of webpack dev server not emitting the file
    // const expireSettings = {
    //   // Cache-Control: private, max-age=604800
    //   maxAge: config.get('browserCacheMaxAge'),
    //   index: false,
    // }
    const clientAssetsPath = getConfigForEnv('publicAssetsPath');
    const mediaAssetsPath = pathResolve(appRootDir, clientAssetsPath);
    expressApp.use(express.static(mediaAssetsPath));
    // Security middlewares.
    expressApp.use(...security);
    expressApp.use(cookieParser());
    expressApp.use(bodyParser.json());
    expressApp.use(bodyParser.urlencoded({
        extended: true,
    }));
    // not needed now
    // expressApp.use(miniRoutingMiddleware)
    expressApp.use(loggerMiddleware);
    // sessions - this can just be a middleware not a plugin right??
    // dynamic.protection = sessionPlugin(expressApp)
}
function setupAppSync(expressApp = app) {
    // testing brotli - could also add a health `ping` here
    /**
     * @see https://bitbucket.org/skava-admin/reference-store/pull-requests/1219/zzz-b2b-mvp-fork/diff#comment-79603865
     * @description The React application middleware.
     * @note respondRedirect was used here
     */
    expressApp.get('/export', exportAccountMiddleware);
    expressApp.use('/ping', pingEndpoint);
    expressApp.get('/*', routingMiddleware, cacheMiddleware, dynamic.protection, reactApplication);
    // Error Handler middlewares.
    expressApp.use(...errorHandlers);
}
function setupApp(expressApp = app) {
    logger.debug('[appserver] setupApp');
    decorateApp(expressApp);
    setupAppSync(expressApp);
    // setupAppAsync(expressApp)
}
function start() {
    const PORT = process.env.PORT || 3000;
    const onListen = () => {
        logger.info('[server] running app on port ', PORT);
    };
    setupApp(app);
    app.listen(PORT, onListen);
}
export { start, decorateApp, setupApp, app };
//# sourceMappingURL=app.js.map