Skip to content

Commit b1461bb

Browse files
committed
feat: v5.2.0
1 parent bfa5d64 commit b1461bb

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodepress",
3-
"version": "5.1.0",
3+
"version": "5.2.0",
44
"description": "RESTful API service for Surmon.me blog",
55
"author": "Surmon",
66
"license": "MIT",

src/app.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export const APP_BIZ = {
4949
FE_URL: 'https://surmon.me',
5050
/** Static resource host URL */
5151
STATIC_URL: 'https://static.surmon.me',
52+
/** Allowed CORS origins */
53+
CORS_ALLOWED_ORIGINS: ['https://surmon.me', /\.surmon\.me$/],
5254
/** Authentication config */
5355
AUTH: {
5456
/** JWT token expiration time in seconds */

src/main.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,36 @@ async function bootstrap() {
4343
request.locals.isUnauthenticated = !isAuthenticated
4444
})
4545

46+
// Enable CORS https://github.com/fastify/fastify-cors
47+
app.enableCors({
48+
// Allow all origins in development, restrict in production
49+
origin: isDevEnv ? true : APP_BIZ.CORS_ALLOWED_ORIGINS,
50+
preflight: true,
51+
credentials: true,
52+
maxAge: 600,
53+
methods: ['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE']
54+
// Defaults to reflecting the headers specified in the request's Access-Control-Request-Headers header if not specified.
55+
// allowedHeaders: [
56+
// 'Authorization',
57+
// 'Origin',
58+
// 'No-Cache',
59+
// 'X-Requested-With',
60+
// 'If-Modified-Since',
61+
// 'Pragma',
62+
// 'Last-Modified',
63+
// 'Cache-Control',
64+
// 'Expires',
65+
// 'Content-Type',
66+
// 'X-E4M-With',
67+
// 'Sentry-Trace',
68+
// 'Baggage'
69+
// ]
70+
})
71+
4672
// Register global filters and interceptors
4773
app.useGlobalFilters(new HttpExceptionFilter())
4874
app.useGlobalInterceptors(new TransformInterceptor())
49-
if (isDevEnv) {
50-
app.useGlobalInterceptors(new LoggingInterceptor())
51-
app.enableCors({
52-
origin: true,
53-
preflight: true,
54-
credentials: true,
55-
maxAge: 86400,
56-
methods: ['GET', 'PUT', 'POST', 'DELETE', 'PATCH']
57-
})
58-
}
75+
if (isDevEnv) app.useGlobalInterceptors(new LoggingInterceptor())
5976

6077
return await app.listen(APP_BIZ.PORT)
6178
}

0 commit comments

Comments
 (0)