mirror of
https://github.com/diced/zipline.git
synced 2026-01-17 07:12:19 -08:00
feat: native ssl
This commit is contained in:
@@ -121,6 +121,10 @@ export const rawConfig: any = {
|
||||
onUpload: undefined,
|
||||
onShorten: undefined,
|
||||
},
|
||||
ssl: {
|
||||
key: undefined,
|
||||
cert: undefined,
|
||||
},
|
||||
};
|
||||
|
||||
export const PROP_TO_ENV = {
|
||||
@@ -246,6 +250,9 @@ export const PROP_TO_ENV = {
|
||||
|
||||
'httpWebhook.onUpload': 'HTTP_WEBHOOK_ONUPLOAD',
|
||||
'httpWebhook.onShorten': 'HTTP_WEBHOOK_ONSHORTEN',
|
||||
|
||||
'ssl.key': 'SSL_KEY',
|
||||
'ssl.cert': 'SSL_CERT',
|
||||
};
|
||||
|
||||
const logger = log('config').c('read');
|
||||
@@ -369,6 +376,9 @@ export function readEnv() {
|
||||
|
||||
env('httpWebhook.onUpload', 'string'),
|
||||
env('httpWebhook.onShorten', 'string'),
|
||||
|
||||
env('ssl.key', 'string'),
|
||||
env('ssl.cert', 'string'),
|
||||
];
|
||||
|
||||
// clone raw
|
||||
|
||||
@@ -279,6 +279,18 @@ export const schema = z.object({
|
||||
onUpload: z.string().url().nullable().default(null),
|
||||
onShorten: z.string().url().nullable().default(null),
|
||||
}),
|
||||
ssl: z.object({
|
||||
key: z
|
||||
.string()
|
||||
.transform((s) => resolve(s))
|
||||
.nullable()
|
||||
.default(null),
|
||||
cert: z
|
||||
.string()
|
||||
.transform((s) => resolve(s))
|
||||
.nullable()
|
||||
.default(null),
|
||||
}),
|
||||
});
|
||||
|
||||
export type Config = z.infer<typeof schema>;
|
||||
|
||||
@@ -24,6 +24,7 @@ import loadRoutes from './routes';
|
||||
import { filesRoute } from './routes/files.dy';
|
||||
import { urlsRoute } from './routes/urls.dy';
|
||||
import { isAdministrator } from '@/lib/role';
|
||||
import { notNull } from '@/lib/primitive';
|
||||
|
||||
const MODE = process.env.NODE_ENV || 'production';
|
||||
const logger = log('server');
|
||||
@@ -52,7 +53,15 @@ async function main() {
|
||||
|
||||
await runMigrations();
|
||||
|
||||
const server = fastify({ ignoreTrailingSlash: true });
|
||||
const server = fastify({
|
||||
ignoreTrailingSlash: true,
|
||||
https: notNull(config.ssl.key, config.ssl.cert)
|
||||
? {
|
||||
key: config.ssl.key!,
|
||||
cert: config.ssl.cert!,
|
||||
}
|
||||
: null,
|
||||
});
|
||||
|
||||
await server.register(fastifyCookie, {
|
||||
secret: config.core.secret,
|
||||
|
||||
Reference in New Issue
Block a user