Skip to content

Commit ef5657b

Browse files
authored
Chore #49 (PR #50)
1 parent e59fcf6 commit ef5657b

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

packages/nextjs/next.config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,25 @@ const nextConfig = {
1616
config.externals.push("pino-pretty", "lokijs", "encoding");
1717
return config;
1818
},
19+
async headers() {
20+
if ('CSP_FRAMES' in process.env) {
21+
return [
22+
{
23+
source: '/:path*',
24+
headers: [
25+
{
26+
key: "Content-Security-Policy",
27+
value: `frame-ancestors ${process.env.CSP_FRAMES}`
28+
}
29+
]
30+
}
31+
]
32+
} else {
33+
return [];
34+
}
35+
},
1936
// the following doesn't seem to work, see instead package.json "build" script containing "tsc --build" and tsconfig.json "refereences" setting
20-
transpilePackages: ['@10tance/map'],
37+
transpilePackages: ['@10tance/map']
2138
};
2239

2340
module.exports = nextConfig;

packages/tileserver/src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import 'dotenv/config';
2-
import express, { Express, Request } from "express";
2+
import express, { Express } from "express";
33
import cors from "cors";
44

55
import {tilesRoute, objectsRoute, tileBasedMiddlewareFactory} from './routes';
66

77
const app: Express = express();
88
const port = process.env.PORT || 3001;
99

10-
app.use(cors());
10+
const ALLOWED_ORIGIN = (process.env.CORS_ORIGIN) ? new RegExp(process.env.CORS_ORIGIN) : false;
11+
12+
app.use(cors({
13+
origin: ALLOWED_ORIGIN,
14+
methods: "GET,HEAD,OPTIONS"
15+
}));
1116

1217
const promise_app = tileBasedMiddlewareFactory()
1318
.then((tileBasedMiddleware) => {
@@ -24,5 +29,4 @@ process.on("exit", () => {
2429
// TODO close db;
2530
})
2631

27-
28-
module.exports = promise_app;
32+
module.exports = promise_app;

packages/tileserver/vercel.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
{ "src": "src/index.ts", "use": "@vercel/node" }
55
],
66
"routes": [
7-
{ "src": "/(.*)", "dest": "src/index.ts" }
7+
{
8+
"src": "/(.*)",
9+
"dest": "src/index.ts",
10+
"methods": ["GET", "OPTIONS", "HEAD"],
11+
"headers": {
12+
"Access-Control-Allow-Credentials": "true",
13+
"Access-Control-Allow-Methods": "GET,OPTIONS,HEAD",
14+
"Access-Control-Allow-Headers": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Origin",
15+
"Cache-Control": "public, max-age=3600, s-maxage=86400, immutable",
16+
"CDN-Cache-Control": "public, s-maxage=86400",
17+
"Vercel-CDN-Cache-Control": "public, s-maxage=86400"
18+
}
19+
}
820
]
921
}

0 commit comments

Comments
 (0)