SPB Git

Repository Public

proxy.ts 2.8 KB 76 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : KA Maps Engine8 * File             : sdk/web/tests/next-app/proxy.ts9 * Module           : sdk10 * Repository       : https://git.spboucher.ai/ka-maps-engine11 * Created          : 2026-12-0112 * Last Modified    : 2026-12-0113 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: support@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// CSP stricte à nonce (recommandation Next.js) + les directives de KA Maps.43// Next.js 16 : ce fichier s'appelle proxy.ts (ex-middleware.ts).44import { NextResponse, type NextRequest } from 'next/server';4546const KA = {47  script: "'wasm-unsafe-eval'",48  worker: "'self'",49  connect: 'https://tiles.spboucher.ai https://terrain.spboucher.ai https://geo.spboucher.ai https://maps.spboucher.ai',50};5152export function proxy(request: NextRequest) {53  const nonce = Buffer.from(crypto.randomUUID()).toString('base64');54  const csp = [55    "default-src 'self'",56    `script-src 'self' 'nonce-${nonce}' 'strict-dynamic' ${KA.script}`,57    `worker-src ${KA.worker}`,58    "style-src 'self'",59    "img-src 'self' data:",60    `connect-src 'self' ${KA.connect}`,61    "object-src 'none'",62    "base-uri 'self'",63    "frame-ancestors 'none'",64  ].join('; ');65  const headers = new Headers(request.headers);66  headers.set('x-nonce', nonce);67  headers.set('Content-Security-Policy', csp);68  const response = NextResponse.next({ request: { headers } });69  response.headers.set('Content-Security-Policy', csp);70  return response;71}7273export const config = {74  matcher: [{ source: '/((?!_next/static|_next/image|favicon.ico|ka-maps/).*)' }],75};76
Files main
Menu

Theme