Skip to content

Commit

Permalink
fix: update local CORS settings requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Dec 19, 2023
1 parent a262f71 commit 8d05046
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 13 deletions.
17 changes: 11 additions & 6 deletions apps/auth/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { AppModule } from './app/app.module';
import { EnvironmentVariables } from './app/env';
import { APP_FOLDER, DEFAULT_PORT } from './app/shared/constants';

// eslint-disable-next-line max-lines-per-function
async function bootstrap(): Promise<void> {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
Expand All @@ -55,10 +56,6 @@ async function bootstrap(): Promise<void> {
const logger = app.get(Logger);
app.useLogger(logger);
app.setGlobalPrefix(GLOBAL_API_PREFIX);
// app.useStaticAssets({
// root: resolve(`dist/${APP_FOLDER}/public`),
// prefix: '/',
// });

// Fastify
await app.register(fastifyHelmet, {
Expand All @@ -77,9 +74,17 @@ async function bootstrap(): Promise<void> {
});
await app.register(fastifyPassport.initialize());
await app.register(fastifyPassport.secureSession());
if (!proxyServerUrls.length) {
if (!proxyServerUrls.length && environment === 'production') {
await app.register(fastifyCors, {
origin: '*',
origin: (origin, cb) => {
const hostname = new URL(origin).hostname;
if (hostname === 'localhost' || hostname === '127.0.0.1') {
cb(null, true);
return;
}
cb(new Error('Not allowed'), false);
},
credentials: true,
// allowedHeaders: ALLOWED_HEADERS,
// exposedHeaders: EXPOSED_HEADERS,
allowedHeaders: '*',
Expand Down
12 changes: 10 additions & 2 deletions apps/orders/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,17 @@ async function bootstrap(): Promise<void> {
});
await app.register(fastifyPassport.initialize());
await app.register(fastifyPassport.secureSession());
if (!proxyServerUrls.length) {
if (!proxyServerUrls.length && environment === 'development') {
await app.register(fastifyCors, {
origin: '*',
origin: (origin, cb) => {
const hostname = new URL(origin).hostname;
if (hostname === 'localhost' || hostname === '127.0.0.1') {
cb(null, true);
return;
}
cb(new Error('Not allowed'), false);
},
credentials: true,
// allowedHeaders: ALLOWED_HEADERS,
// exposedHeaders: EXPOSED_HEADERS,
allowedHeaders: '*',
Expand Down
11 changes: 9 additions & 2 deletions apps/payments/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,16 @@ async function bootstrap(): Promise<void> {
});
await app.register(fastifyPassport.initialize());
await app.register(fastifyPassport.secureSession());
if (!proxyServerUrls.length) {
if (!proxyServerUrls.length && environment === 'development') {
await app.register(fastifyCors, {
origin: '*',
origin: (origin, cb) => {
const hostname = new URL(origin).hostname;
if (hostname === 'localhost') {
cb(null, true);
return;
}
cb(new Error('Not allowed'), false);
},
// allowedHeaders: ALLOWED_HEADERS,
// exposedHeaders: EXPOSED_HEADERS,
allowedHeaders: '*',
Expand Down
12 changes: 10 additions & 2 deletions apps/tickets/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,17 @@ async function bootstrap(): Promise<void> {
});
await app.register(fastifyPassport.initialize());
await app.register(fastifyPassport.secureSession());
if (!proxyServerUrls.length) {
if (!proxyServerUrls.length && environment === 'development') {
await app.register(fastifyCors, {
origin: '*',
origin: (origin, cb) => {
const hostname = new URL(origin).hostname;
if (hostname === 'localhost' || hostname === '127.0.0.1') {
cb(null, true);
return;
}
cb(new Error('Not allowed'), false);
},
credentials: true,
// allowedHeaders: ALLOWED_HEADERS,
// exposedHeaders: EXPOSED_HEADERS,
allowedHeaders: '*',
Expand Down
4 changes: 3 additions & 1 deletion libs/microservices/shared/constants/src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const bearerSecurityScheme: SecuritySchemeObject = {
};

export const getCookieOptions = (
environment: Environment
environment: Environment,
): CookieSerializeOptions => ({
secure: !devEnvironments.includes(environment),
signed: false,
Expand All @@ -36,7 +36,9 @@ export const ALLOWED_HEADERS = [
'X-Version',
'X-Access-Token',
'X-Refresh-Token',
'Authorization',
'Set-Cookie',
'Cookie',
'DNT',
'User-Agent',
'X-Requested-With',
Expand Down

0 comments on commit 8d05046

Please sign in to comment.