Skip to content

Commit

Permalink
Add fastify private network fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pozylon committed Nov 27, 2024
1 parent 10bb765 commit 445f073
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/kitchensink/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const { UNCHAINED_COOKIE_NAME = 'unchained_token' } = process.env;
const start = async () => {
const app = express();

// Workaround Express Secure Proxy
// Workaround: Allow to use sandbox with localhost
app.set('trust proxy', 1);
app.use((req, res, next) => {
req.headers['x-forwarded-proto'] = 'https';
Expand Down
1 change: 1 addition & 0 deletions examples/minimal/.env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ UNCHAINED_SECRET=secret
UNCHAINED_CLOUD_ENDPOINT=https://engine.unchained.shop/graphql
UNCHAINED_TOKEN_SECRET=random-token-that-is-not-secret-at-all
UNCHAINED_COOKIE_SAMESITE=none
UNCHAINED_COOKIE_INSECURE=
REDIS_DB=0
MONGOMS_VERSION=8.0.1
12 changes: 12 additions & 0 deletions examples/minimal/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import Fastify from 'fastify';
const start = async () => {
const fastify = Fastify({
logger: true,
trustProxy: true,
});

// Workaround: Allow to use sandbox with localhost
fastify.addHook('preHandler', async function (request) {
request.headers['x-forwarded-proto'] = 'https';
});

fastify.addHook('onSend', async function (_, reply) {
reply.headers({
'Access-Control-Allow-Private-Network': 'true',
});
});

const engine = await startPlatform({
Expand Down
9 changes: 0 additions & 9 deletions packages/api/src/fastify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ export const connect = (
'0': false,
}[UNCHAINED_COOKIE_SAMESITE?.trim()?.toLowerCase()] || false) as boolean | 'none' | 'lax' | 'strict';

console.log({
domain,
httpOnly: true,
path,
secure,
sameSite,
maxAge: 1000 * 60 * 60 * 24 * 7,
});

fastify.register(fastifyCookie);
fastify.register(fastifySession, {
secret: process.env.UNCHAINED_TOKEN_SECRET,
Expand Down

0 comments on commit 445f073

Please sign in to comment.