chore: move http headers to separate config variable

This commit is contained in:
Vjacheslav Trushkin 2022-11-04 18:24:43 +02:00
parent ee16dbd6cf
commit ec906825e5
5 changed files with 17 additions and 24 deletions

View File

@ -88,7 +88,7 @@ By default, server sends the following HTTP headers:
- Various CORS headers, allowing access from anywhere.
- Cache headers to cache responses for 604800 seconds (7 days).
To change headers, edit `headers` property in `src/config/app.ts`, then rebuild script.
To change headers, edit `httpHeaders` variable in `src/config/app.ts`, then rebuild script.
## Node vs PHP

View File

@ -15,18 +15,6 @@ export const appConfig: AppConfig = {
// Cache root directory
cacheRootDir: 'cache',
// HTTP headers to send
headers: [
// CORS
'Access-Control-Allow-Origin: *',
'Access-Control-Allow-Methods: GET, OPTIONS',
'Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Accept-Encoding',
'Access-Control-Max-Age: 86400',
'Cross-Origin-Resource-Policy: cross-origin',
// Cache
'Cache-Control: public, max-age=604800, min-refresh=604800, immutable',
],
// Host and port for server
host: '0.0.0.0',
port: 3000,
@ -59,6 +47,20 @@ export const appConfig: AppConfig = {
allowFilterIconsByStyle: true,
};
/**
* HTTP headers to send to visitors
*/
export const httpHeaders: string[] = [
// CORS
'Access-Control-Allow-Origin: *',
'Access-Control-Allow-Methods: GET, OPTIONS',
'Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Accept-Encoding',
'Access-Control-Max-Age: 86400',
'Cross-Origin-Resource-Policy: cross-origin',
// Cache
'Cache-Control: public, max-age=604800, min-refresh=604800, immutable',
];
/**
* Splitting icon sets
*/

View File

@ -1,5 +1,5 @@
import fastify from 'fastify';
import { appConfig } from '../config/app';
import { appConfig, httpHeaders } from '../config/app';
import { runWhenLoaded } from '../data/loading';
import { iconNameRoutePartialRegEx, iconNameRouteRegEx, splitIconName } from '../misc/name';
import { generateAPIv1IconsListResponse } from './responses/collection-v1';
@ -28,7 +28,7 @@ export async function startHTTPServer() {
value: string;
}
const headers: Header[] = [];
appConfig.headers.forEach((item) => {
httpHeaders.forEach((item) => {
const parts = item.split(':');
if (parts.length > 1) {
headers.push({

View File

@ -33,12 +33,6 @@ export function loadEnvConfig(env = process.env) {
case 'string':
cfg[key] = value;
break;
case 'object':
if (defaultValue instanceof Array) {
// Append one entry to array
defaultValue.push(value);
}
}
}
}

View File

@ -12,9 +12,6 @@ export interface AppConfig {
// Without trailing '/'
cacheRootDir: string;
// HTTP headers to send
headers: string[];
// Host
host: string;