121 lines
3.1 KiB
Bash
Executable File
121 lines
3.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Set default storage type to Redis unless specified otherwise
|
|
STORAGE_TYPE=${STORAGE_TYPE:-redis}
|
|
|
|
# Conditional installations based on STORAGE_TYPE
|
|
case "${STORAGE_TYPE}" in
|
|
"redis")
|
|
echo "Installing Redis..."
|
|
npm install redis
|
|
;;
|
|
"postgres")
|
|
echo "Installing PostgreSQL..."
|
|
npm install pg
|
|
;;
|
|
"memcached")
|
|
echo "Installing Memcached..."
|
|
npm install memcached
|
|
;;
|
|
"rethinkdb")
|
|
echo "Installing RethinkDB..."
|
|
npm install rethinkdbdash
|
|
;;
|
|
esac
|
|
|
|
# Generate config.js from environment variables
|
|
cat > config.js <<EOF
|
|
const config = {
|
|
// Server settings
|
|
host: "${HOST:-0.0.0.0}",
|
|
port: ${PORT:-7777},
|
|
keyLength: ${KEY_LENGTH:-10},
|
|
maxLength: ${MAX_LENGTH:-400000},
|
|
staticMaxAge: ${STATIC_MAX_AGE:-86400},
|
|
recompressStaticAssets: ${RECOMPRESS_STATIC_ASSETS:-true},
|
|
|
|
// Security settings
|
|
security: {
|
|
// Enable Content Security Policy
|
|
csp: ${HASTEBIN_ENABLE_CSP:-true},
|
|
|
|
// Enable HTTP Strict Transport Security (only enable in production with HTTPS)
|
|
hsts: ${HASTEBIN_ENABLE_HSTS:-false},
|
|
|
|
// Additional script sources (empty by default since we now host jQuery locally)
|
|
scriptSources: "${HASTEBIN_SCRIPT_SOURCES:-}".split(',').filter(Boolean),
|
|
|
|
// Allow bypassing strict CSP in development mode for testing (default: false)
|
|
bypassCSPInDev: ${HASTEBIN_BYPASS_CSP_IN_DEV:-false},
|
|
|
|
// Allow unsafe-hashes in production for event handlers (default: true)
|
|
allowUnsafeHashes: ${HASTEBIN_ALLOW_UNSAFE_HASHES:-true},
|
|
|
|
// Enable Cross-Origin isolation headers (default: false)
|
|
enableCrossOriginIsolation: ${HASTEBIN_ENABLE_CROSS_ORIGIN_ISOLATION:-false}
|
|
},
|
|
|
|
// Logging configuration
|
|
logging: [
|
|
{
|
|
level: "${LOGGING_LEVEL:-verbose}",
|
|
type: "${LOGGING_TYPE:-Console}",
|
|
colorize: ${LOGGING_COLORIZE:-false},
|
|
json: ${LOGGING_JSON:-false}
|
|
}
|
|
],
|
|
|
|
// Key generator configuration
|
|
keyGenerator: {
|
|
type: "${KEY_GENERATOR_TYPE:-phonetic}"
|
|
},
|
|
|
|
// Rate limiting configuration
|
|
rateLimits: {
|
|
categories: {
|
|
normal: {
|
|
totalRequests: ${RATE_LIMIT_TOTAL_REQUESTS:-500},
|
|
every: ${RATE_LIMIT_WINDOW:-60000}
|
|
}
|
|
}
|
|
},
|
|
|
|
// Storage configuration
|
|
storage: {
|
|
type: "${STORAGE_TYPE:-redis}",
|
|
path: "${STORAGE_PATH:-./data}",
|
|
host: "${STORAGE_HOST:-redis}",
|
|
port: ${STORAGE_PORT:-6379},
|
|
password: "${STORAGE_PASSWORD:-}",
|
|
db: ${STORAGE_DB:-0},
|
|
expire: ${STORAGE_EXPIRE:-7776000}
|
|
},
|
|
|
|
// Static documents
|
|
documents: {
|
|
about: "${ABOUT_DOCUMENT:-./about.md}"
|
|
},
|
|
|
|
// CORS settings
|
|
allowedOrigins: "${HASTEBIN_ALLOWED_ORIGINS:-*}".split(',')
|
|
};
|
|
|
|
// Support for backwards compatibility
|
|
if (process.env.REDIS_URL || process.env.REDISTOGO_URL) {
|
|
config.storage.url = process.env.REDIS_URL || process.env.REDISTOGO_URL;
|
|
}
|
|
|
|
module.exports = config;
|
|
EOF
|
|
|
|
# If TEST_MODE is true, install Mocha and run tests
|
|
if [ "$TEST_MODE" = "true" ]; then
|
|
echo "Installing Mocha for testing..."
|
|
npm install mocha
|
|
echo "Running tests..."
|
|
npm test
|
|
npm audit
|
|
else
|
|
# Start the server for normal run
|
|
exec node server.js
|
|
fi |