mirror of https://github.com/iconify/api.git
chore: move http headers to separate config variable
This commit is contained in:
parent
ee16dbd6cf
commit
ec906825e5
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,6 @@ export interface AppConfig {
|
|||
// Without trailing '/'
|
||||
cacheRootDir: string;
|
||||
|
||||
// HTTP headers to send
|
||||
headers: string[];
|
||||
|
||||
// Host
|
||||
host: string;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue