Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import querystring from 'qs';
import config from 'mwp-config';
const appConfig = config.getServer().properties;
export const MEMBER_COOKIE = appConfig.api.isProd
? 'MEETUP_MEMBER'
: 'MEETUP_MEMBER_DEV';
export const BROWSER_ID_COOKIE = appConfig.api.isProd
? 'MEETUP_BROWSER_ID'
: 'MEETUP_BROWSER_ID_DEV';
// SIFT_SESSION_ID cookie created in fastly and used by sift science to correlate spammy
// behavior to user activity; cookie has an expiration time of 4 hours and should be
// reset on logout. For more details please refer https://sift.com/resources/tutorials/anonymous-users
export const SIFT_SESSION_COOKIE = appConfig.api.isProd
? 'SIFT_SESSION_ID'
: 'SIFT_SESSION_ID_DEV';
import './util/globals';
import fs from 'fs';
import Http2 from 'spdy'; // eventually this will be a native node module
import config from 'mwp-config';
import getRoutes from './routes';
import getPlugins from './util/getPlugins';
import { configureEnv, server } from './util';
const appConfig = config.getServer().properties;
/**
* @module server
*/
/**
* The start function applies the rendering function to the correct application
* route and combines the provided routes and plugins with the base routes
* and plugins
*
* @param {Object} languageRenderers A mapping of localeCodes to functions that emit
* the rendered HTML for the locale-specific request
* @param {Array} routes additional routes for the app - cannot include a
* wildcard route
* @param {Array} plugins additional plugins for the server, usually to support
* features in the additional routes
export function parseRequestHeaders(request) {
const externalRequestHeaders = {
...request.headers,
...getAuthHeaders(request),
...getClientIpHeader(request),
...getTrackingHeaders(request),
'accept-language': getLanguageHeader(request),
'x-meetup-agent': config.package.agent,
'x-meetup-parent-request-id': request.id,
};
delete externalRequestHeaders['host']; // let app server set 'host'
delete externalRequestHeaders['accept-encoding']; // let app server set 'accept'
delete externalRequestHeaders['content-length']; // original request content-length is irrelevant
delete externalRequestHeaders['content-type']; // the content type will be set in buildRequestArgs
return externalRequestHeaders;
}
export function parseRequestHeaders(request) {
const externalRequestHeaders = {
...request.headers,
...getAuthHeaders(request),
...getClientIpHeader(request),
...getTrackingHeaders(request),
'accept-language': getLanguageHeader(request),
'x-meetup-agent': config.package.agent,
'x-meetup-parent-request-id': request.id,
};
delete externalRequestHeaders['host']; // let app server set 'host'
delete externalRequestHeaders['accept-encoding']; // let app server set 'accept'
delete externalRequestHeaders['content-length']; // original request content-length is irrelevant
delete externalRequestHeaders['content-type']; // the content type will be set in buildRequestArgs
return externalRequestHeaders;
}
// @flow
const buildPaths = require('mwp-config').paths;
const path = require('path');
/*
* The service worker plugin will register a root-level route for serving the
* service worker script file.
*
* Disk location of the script file is determined by builder CLI config import.
*/
export function register(server: Object, options: ?Object) {
/*
* Route for service worker script at top-level path. Depends on `Inert`
* `path` must match client `serviceWorker.register` call - MWP provides this
* in the `` component
*/
server.route({
method: 'GET',
import csrf from 'electrode-csrf-jwt/lib/csrf';
import uuid from 'uuid';
import config from 'mwp-config';
import makeRenderer from 'mwp-core/lib/server-render';
const appConfig = config.getServer().properties;
import { clientFilename, routes, reducer } from 'mwp-test-utils/lib/mockApp';
export const getMockFetch = (mockResponseValue = { responses: [{}] }, headers = {}) =>
Promise.resolve({
text: () => Promise.resolve(JSON.stringify(mockResponseValue)),
json: () => Promise.resolve(mockResponseValue),
headers: {
get: key => headers[key],
},
});
export function getCsrfHeaders() {
const options = {
secret: appConfig.csrf_secret,
};
import { getServer } from 'mwp-config';
export const API_PROXY_PLUGIN_NAME = 'mwp-api-proxy-plugin';
export const API_ROUTE_PATH = getServer().properties.app_server.api_proxy_path;
export const generateCanonicalUrlLinkTags = (baseUrl, localeCode, route) => {
const localeLinks = locales.map(locale => (
));
return [
...localeLinks,
,
export const generateCanonicalUrlMetaTags = (baseUrl, localeCode, route) => {
const localeLinks = locales.map(locale => (
));
return [
...localeLinks,
,
handler: (request, h) => {
const { localeCode } = request.params;
const swPath = path.resolve(
buildPaths.output.browser,
localeCode,
'asset-service-worker.js'
);
return h.file(swPath);
},
});