All files / src config.ts

100% Statements 9/9
100% Branches 18/18
100% Functions 2/2
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78      1x                                                                 9x     9x     1x   1x     8x                     2x     2x     6x                          
import * as express from 'express';
 
/** Local Configs */
export const FUNCTIONS_CONFIG = {
    /** supported culture codes; ['en', 'tr'] */
    supportedCultureCodes: ['en-US', 'tr-TR'],
    /** supported language codes; ['en', 'tr'] */
    supportedLanguageCodes: ['en', 'tr'],
    /** default language code to redirect; en, tr */
    defaultLanguageCode: 'tr',
    /** do you want to cache responses? */
    cacheResponses: false,
    /**
     * options for cors
     * https://www.npmjs.com/package/cors#configuration-options
     */
    cors: { origin: true },
    /**
     * options for helmet-csp
     * https://www.npmjs.com/package/helmet-csp
     */
    csp: {
        directives: {
            defaultSrc: ["'self'", '*.googleapis.com', '*.google-analytics.com'],
            imgSrc: [
                "'self'", 'data:', '*.googleapis.com', '*.google.com',
                '*.google.com.tr', '*.google-analytics.com', '*.doubleclick.net'],
            styleSrc: ["'self'", "'unsafe-inline'", '*.google.com'],
            scriptSrc: ["'self'", "'unsafe-inline'", "'unsafe-eval'", '*.googletagmanager.com', '*.google-analytics.com', '*.google.com']
        }
    },
    /**
     * check if request is valid
     * resolve true if it is OK
     * resolve false if it is Invalid or Bad
     */
    isRequestValid: async (req: express.Request, res: express.Response, send404Page: (req1, res1) => Promise<void>): Promise<boolean> => {
        // this is only for old php web site but keeping them forever would be better in case of search engines
        // a url like that won't be ok anymore
        if (req.url.indexOf('?page') > -1 ||
            req.url.indexOf('.php?') > -1 ||
            req.url.endsWith('/all/feed')) {
            await send404Page(req, res);
 
            return Promise.resolve(false);
        }
        // this is for lost person, we may be in attach, so no need to use more resource
        if (req.path.indexOf('%20') > -1 || // ' '
            req.path.indexOf('%22') > -1 || // "
            req.path.indexOf('%27') > -1 || // '
            req.path.indexOf('=') > -1 ||
            req.url.startsWith('/modules/') ||
            req.url.startsWith('/sites/') ||
            req.url.startsWith('/wp-') ||
            req.url.indexOf('login.') > -1 ||
            req.url.indexOf('admin.') > -1 ||
            req.url.indexOf('/.env') > -1 ||
            req.url.indexOf('.conf') > -1) {
            res.status(404)
                .send('<p>Invalid Url!</p><p>If you lost</p> <a href="/">Go to Home Page</a>');
 
            return Promise.resolve(false);
        }
 
        return Promise.resolve(true);
    },
    /** http port to run unit test */
    unitTestHttpPort: 5100
};
 
// istanbul ignore next
if (process.env.IS_RUNNING_ON_LOCALHOST) {
    console.log('FUNCTIONS_CONFIG SET FOR LOCALHOST');
} else {
    FUNCTIONS_CONFIG.cacheResponses = true;
    console.log('FUNCTIONS_CONFIG SET FOR LIVE');
}