diff --git a/src/lostcity/routes/about/index.js b/src/lostcity/routes/about/index.js index 5d7df6fc..3b0156ec 100644 --- a/src/lostcity/routes/about/index.js +++ b/src/lostcity/routes/about/index.js @@ -1,18 +1,20 @@ +import Environment from '#lostcity/util/Environment.js'; + export default function (f, opts, next) { f.get('/', async (req, res) => { - return res.view('about/index'); + return res.view('about/index', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); f.get('/getstart', async (req, res) => { - return res.view('about/getstart'); + return res.view('about/getstart', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); f.get('/virtual', async (req, res) => { - return res.view('about/virtual'); + return res.view('about/virtual', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); f.get('/whatisrs', async (req, res) => { - return res.view('about/whatisrs'); + return res.view('about/whatisrs', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); next(); diff --git a/src/lostcity/routes/create/index.ts b/src/lostcity/routes/create/index.ts index 04d7f69e..48420346 100644 --- a/src/lostcity/routes/create/index.ts +++ b/src/lostcity/routes/create/index.ts @@ -4,6 +4,8 @@ import { toDisplayName, toSafeName } from '#jagex2/jstring/JString.js'; import { db } from '#lostcity/db/query.js'; +import Environment from '#lostcity/util/Environment.js'; + enum CreateStep { USERNAME, TERMS, @@ -37,14 +39,17 @@ export default function (f: any, opts: any, next: any) { delete req.session.createUsername; return res.view('create/username', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, error: createError }); } else if (createStep === CreateStep.TERMS) { return res.view('create/terms', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, username: createUsername }); } else if (createStep === CreateStep.PASSWORD) { return res.view('create/password', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, username: createUsername, error: createError }); @@ -52,7 +57,7 @@ export default function (f: any, opts: any, next: any) { delete req.session.createStep; delete req.session.createUsername; - return res.view('create/finish'); + return res.view('create/finish', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); } }); diff --git a/src/lostcity/routes/mod/index.ts b/src/lostcity/routes/mod/index.ts index 4752945d..39fefc9d 100644 --- a/src/lostcity/routes/mod/index.ts +++ b/src/lostcity/routes/mod/index.ts @@ -1,4 +1,5 @@ import { db } from '#lostcity/db/query.js'; +import Environment from '#lostcity/util/Environment.js'; export default function (f: any, opts: any, next: any) { f.get('/session/:username', async (req: any, res: any) => { @@ -8,6 +9,7 @@ export default function (f: any, opts: any, next: any) { const account = await db.selectFrom('account').where('username', '=', username).selectAll().executeTakeFirstOrThrow(); return res.view('mod/session', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, account, logs: await db.selectFrom('account_session').where('account_id', '=', account.id).orderBy('timestamp desc').limit(100).selectAll().execute() }); diff --git a/src/lostcity/routes/news/index.ts b/src/lostcity/routes/news/index.ts index b0a05b33..3ca8495d 100644 --- a/src/lostcity/routes/news/index.ts +++ b/src/lostcity/routes/news/index.ts @@ -58,6 +58,7 @@ export default function (f: any, opts: any, next: any) { newsposts = newsposts.limit(17); return res.view('news/index', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, category, page, more, @@ -78,6 +79,7 @@ export default function (f: any, opts: any, next: any) { const next = await db.selectFrom('newspost').where('id', '>', req.params.id).where('category_id', '=', newspost.category_id).orderBy('id', 'asc').select('id').executeTakeFirst(); return res.view('news/post', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, newspost, category, date: niceDate(newspost.date), @@ -105,6 +107,7 @@ export default function (f: any, opts: any, next: any) { const newspost = await db.selectFrom('newspost').where('id', '=', post).selectAll().executeTakeFirst(); if (newspost) { return res.view('news/create', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, categories, date: niceDate(newspost.date), post, @@ -114,6 +117,7 @@ export default function (f: any, opts: any, next: any) { } return res.view('news/create', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, categories }); }); @@ -160,6 +164,7 @@ export default function (f: any, opts: any, next: any) { const categories = await db.selectFrom('newspost_category').selectAll().execute(); return res.view('news/create', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, categories, post, date: niceDate(new Date()), @@ -183,6 +188,7 @@ export default function (f: any, opts: any, next: any) { const newspost = await db.selectFrom('newspost').where('id', '=', post).selectAll().executeTakeFirst(); if (newspost) { return res.view('news/create', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, categories, post, newspost, @@ -195,6 +201,7 @@ export default function (f: any, opts: any, next: any) { } return res.view('news/create', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, categories, post, date: niceDate(new Date()), diff --git a/src/lostcity/routes/player/index.ts b/src/lostcity/routes/player/index.ts index 90904256..3b6fb86c 100644 --- a/src/lostcity/routes/player/index.ts +++ b/src/lostcity/routes/player/index.ts @@ -1,4 +1,5 @@ import { db } from '#lostcity/db/query.js'; +import Environment from '#lostcity/util/Environment.js'; import LoggerEventType from '#lostcity/util/LoggerEventType.js'; export default function (f: any, opts: any, next: any) { @@ -9,6 +10,7 @@ export default function (f: any, opts: any, next: any) { const account = await db.selectFrom('account').where('username', '=', username).selectAll().executeTakeFirstOrThrow(); return res.view('player/adventurelog', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, account, logs: await db.selectFrom('account_session').where('account_id', '=', account.id).where('event_type', '=', LoggerEventType.ADVENTURE).orderBy('timestamp desc').limit(100).selectAll().execute() }); diff --git a/src/lostcity/routes/website.js b/src/lostcity/routes/website.js index 9e10e3f2..aa3b0adb 100644 --- a/src/lostcity/routes/website.js +++ b/src/lostcity/routes/website.js @@ -6,11 +6,11 @@ import Environment from '#lostcity/util/Environment.js'; export default function (f, opts, next) { f.get('/', async (req, res) => { - return res.view('index'); + return res.view('index', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); f.get('/disclaimer', async (req, res) => { - return res.view('disclaimer'); + return res.view('disclaimer', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); f.get('/title', async (req, res) => { @@ -21,6 +21,7 @@ export default function (f, opts, next) { const latestNews = Environment.DB_HOST ? await db.selectFrom('newspost').orderBy('id', 'desc').limit(5).selectAll().execute() : []; return res.view('title', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, playerCount, newsposts: latestNews }); @@ -59,6 +60,7 @@ export default function (f, opts, next) { } return res.view('serverlist', { + HTTPS_ENABLED: Environment.HTTPS_ENABLED, detail: typeof req.query['hires.x'] !== 'undefined' ? 'high' : 'low', method: req.query.method, worlds: WorldList, @@ -74,7 +76,7 @@ export default function (f, opts, next) { }); f.get('/cookies', async (req, res) => { - return res.view('cookies'); + return res.view('cookies', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); f.get('/copyright', async (req, res) => { @@ -82,7 +84,7 @@ export default function (f, opts, next) { }); f.get('/detail', async (req, res) => { - return res.view('detail'); + return res.view('detail', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); f.get('/manual', async (req, res) => { @@ -90,7 +92,7 @@ export default function (f, opts, next) { }); f.get('/privacy', async (req, res) => { - return res.view('privacy'); + return res.view('privacy', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); f.get('/support', async (req, res) => { @@ -98,11 +100,11 @@ export default function (f, opts, next) { }); f.get('/terms', async (req, res) => { - return res.view('terms'); + return res.view('terms', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); f.get('/whychoosers', async (req, res) => { - return res.view('whychoosers'); + return res.view('whychoosers', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); f.get('/worldmap', async (req, res) => { @@ -110,7 +112,7 @@ export default function (f, opts, next) { }); f.get('/downloads', async (req, res) => { - return res.view('downloads'); + return res.view('downloads', {HTTPS_ENABLED: Environment.HTTPS_ENABLED}); }); next(); diff --git a/src/lostcity/util/dockerWorldsConf.js b/src/lostcity/util/dockerWorldsConf.js new file mode 100644 index 00000000..ed64d4be --- /dev/null +++ b/src/lostcity/util/dockerWorldsConf.js @@ -0,0 +1,29 @@ +/** + * @fileoverview + * This script dynamically loads a world configuration file from the Server repo. + * + * Purpose: + * - This script loads worlds file dynamically from server repo + * - Its meant to be used only with docker production build + * + * Why? + * - You don't have to pull and modify Website repository just to configure your worlds + * - Simplifies running prod setup + * - Keeps the Server repo as the single source +*/ + +import fs from 'fs'; +import path from 'path'; +import worldConfig from '/usr/src/prodWorldsConf.js'; + +const filePath = path.resolve('/usr/src/app/data/config/worlds.json'); + +fs.mkdirSync(path.dirname(filePath), {recursive: true}); +fs.writeFileSync(filePath, JSON.stringify(worldConfig, null, 2)); + +console.log('[INFO] Worlds config generated! Much wow '); +console.log(` + (\\(\\ + ( -.-) ☆彡 + o_(")(") You're a star!\n` +); diff --git a/view/_partial/header.ejs b/view/_partial/header.ejs index 55d5c026..5bfacb8a 100644 --- a/view/_partial/header.ejs +++ b/view/_partial/header.ejs @@ -38,7 +38,13 @@ <% // https://stackoverflow.com/a/4723302 %> <% // https://stackoverflow.com/a/6222280 %> - + <% if (HTTPS_ENABLED) { %> + + <% } %>