mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Add a precheck file to throw when config is wrong
This commit is contained in:
parent
4f57ac0352
commit
34acc99000
2 changed files with 23 additions and 0 deletions
22
src/precheck.ts
Normal file
22
src/precheck.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { Conf } from '@/config.ts';
|
||||||
|
|
||||||
|
/** Ensure the media URL is not on the same host as the local domain. */
|
||||||
|
function checkMediaHost() {
|
||||||
|
const { url, mediaDomain } = Conf;
|
||||||
|
const mediaUrl = new URL(mediaDomain);
|
||||||
|
|
||||||
|
if (url.host === mediaUrl.host) {
|
||||||
|
throw new PrecheckError('For security reasons, MEDIA_DOMAIN cannot be on the same host as LOCAL_DOMAIN.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Error class for precheck errors. */
|
||||||
|
class PrecheckError extends Error {
|
||||||
|
constructor(message: string) {
|
||||||
|
super(`${message}\nTo disable this check, set DITTO_PRECHECK="false"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Deno.env.get('DITTO_PRECHECK') !== 'false') {
|
||||||
|
checkMediaHost();
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import './precheck.ts';
|
||||||
import app from './app.ts';
|
import app from './app.ts';
|
||||||
|
|
||||||
Deno.serve(app.fetch);
|
Deno.serve(app.fetch);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue