Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
before(app) {
app.set('views', devAuthentication.views);
app.set('view engine', devAuthentication.config.viewEngine);
// This lets us open files from the runtime error overlay.
app.use(errorOverlayMiddleware());
// This service worker file is effectively a 'no-op' that will reset any
// previous service worker registered for the same host:port combination.
// We do this in development to avoid hitting the production cache if
// it used the same host and port.
// https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
app.use(noopServiceWorkerMiddleware());
app.use('/api/graphql', (request, response) => {
response.statusCode = 400;
response.setHeader('Content-Type', 'application/json');
const errorMessage = `This GraphQL endpoint is not available in ${process.env.NODE_ENV} mode as it's not necessary. The menu configuration is loaded from the file "menu.json" (more info at https://www.npmjs.com/package/@commercetools-frontend/application-shell). In case you do need to test things out, you can pass a "mcProxyApiUrl" to your "env.json" and point it to e.g. "https://mc.commercetools.com/api/graphql"`;
const fakeApolloError = new Error(errorMessage);
response.end(
JSON.stringify({
data: null,
// Explicitly check if the request is asking for the `index.html`
// to avoid letting it be served by the static middleware without
// the proper security headers.
.use((request, response, next) => {
if (request.url === '/' || request.url.startsWith('/index.html'))
serverIndexMiddleware(request, response);
else next();
})
// Try serving a static file that matches the url, otherwise go to
// the next middleware (e.g. favicon.png)
.use(express.static(options.paths.publicAssetsPath))
// Catch all middleware to serve the `index.html` (for SPA routes)
.use('*', serverIndexMiddleware);
app.set('views', devAuthentication.views);
app.set('view engine', devAuthentication.config.viewEngine);
return app;
};
before(app) {
app.set('views', devAuthentication.views);
app.set('view engine', devAuthentication.config.viewEngine);
// This lets us open files from the runtime error overlay.
app.use(errorOverlayMiddleware());
// This service worker file is effectively a 'no-op' that will reset any
// previous service worker registered for the same host:port combination.
// We do this in development to avoid hitting the production cache if
// it used the same host and port.
// https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
app.use(noopServiceWorkerMiddleware());
app.use('/api/graphql', (request, response) => {
response.statusCode = 400;
response.setHeader('Content-Type', 'application/json');
const errorMessage = `This GraphQL endpoint is not available in ${process.env.NODE_ENV} mode as it's not necessary. The menu configuration is loaded from the file "menu.json" (more info at https://www.npmjs.com/package/@commercetools-frontend/application-shell). In case you do need to test things out, you can pass a "mcProxyApiUrl" to your "env.json" and point it to e.g. "https://mc.commercetools.com/api/graphql"`;
const fakeApolloError = new Error(errorMessage);
response.end(
JSON.stringify({
.use(compression())
// Explicitly check if the request is asking for the `index.html`
// to avoid letting it be served by the static middleware without
// the proper security headers.
.use((request, response, next) => {
if (request.url === '/' || request.url.startsWith('/index.html'))
serverIndexMiddleware(request, response);
else next();
})
// Try serving a static file that matches the url, otherwise go to
// the next middleware (e.g. favicon.png)
.use(express.static(options.paths.publicAssetsPath))
// Catch all middleware to serve the `index.html` (for SPA routes)
.use('*', serverIndexMiddleware);
app.set('views', devAuthentication.views);
app.set('view engine', devAuthentication.config.viewEngine);
return app;
};
app.use('/logout', (request, response, next) => {
devAuthentication.routes.logout(response);
if (localEnv.disableAuthRoutesOfDevServer) {
next();
} else {
response.render('logout', { env: localEnv });
}
});
},
module.exports = env => (request, response, next) => {
if (!env.servedByProxy) {
devAuthentication.routes.logout(response);
response.render('logout', { env });
} else {
next();
}
};