1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-26 18:58:21 +02:00

Server: Add version number on website

This commit is contained in:
Laurent Cozic 2021-05-26 15:53:27 +02:00
parent ee0f23718b
commit 0ef7e98479
9 changed files with 72 additions and 66 deletions

View File

@ -10,10 +10,6 @@ input.form-control {
margin-bottom: 0.5rem; margin-bottom: 0.5rem;
} }
.navbar {
padding: 1rem 3rem;
}
.navbar .logo-container { .navbar .logo-container {
align-items: center; align-items: center;
} }
@ -34,7 +30,7 @@ input.form-control {
} }
.main { .main {
padding: 0 3rem; padding: 2rem 3rem;
} }
table.table .nowrap { table.table .nowrap {
@ -48,3 +44,13 @@ table.table .stretch {
table.table th .sort-button i { table.table th .sort-button i {
margin-left: 0.5rem; margin-left: 0.5rem;
} }
.footer {
background-color: transparent;
}
.footer .container {
display: flex;
justify-content: flex-end;
opacity: 0.5;
}

View File

@ -16,7 +16,6 @@ import ownerHandler from './middleware/ownerHandler';
import setupAppContext from './utils/setupAppContext'; import setupAppContext from './utils/setupAppContext';
import { initializeJoplinUtils } from './utils/joplinUtils'; import { initializeJoplinUtils } from './utils/joplinUtils';
import startServices from './utils/startServices'; import startServices from './utils/startServices';
// import { createItemTree } from './utils/testing/testUtils';
const nodeEnvFile = require('node-env-file'); const nodeEnvFile = require('node-env-file');
const { shimInit } = require('@joplin/lib/shim-init-node.js'); const { shimInit } = require('@joplin/lib/shim-init-node.js');
@ -87,7 +86,7 @@ async function main() {
if (!envVariables[env]) throw new Error(`Invalid env: ${env}`); if (!envVariables[env]) throw new Error(`Invalid env: ${env}`);
initConfig({ await initConfig({
...envVariables[env], ...envVariables[env],
...process.env, ...process.env,
}); });
@ -127,7 +126,7 @@ async function main() {
} else if (argv.createDb) { } else if (argv.createDb) {
await createDb(config().database); await createDb(config().database);
} else { } else {
appLogger().info(`Starting server (${env}) on port ${config().port} and PID ${process.pid}...`); appLogger().info(`Starting server v${config().appVersion} (${env}) on port ${config().port} and PID ${process.pid}...`);
appLogger().info('Running in Docker:', runningInDocker()); appLogger().info('Running in Docker:', runningInDocker());
appLogger().info('Public base URL:', config().baseUrl); appLogger().info('Public base URL:', config().baseUrl);
appLogger().info('API base URL:', config().apiBaseUrl); appLogger().info('API base URL:', config().apiBaseUrl);
@ -153,38 +152,8 @@ async function main() {
appLogger().info('Starting services...'); appLogger().info('Starting services...');
await startServices(appContext); await startServices(appContext);
// if (env !== Env.Prod) {
// const done = await handleDebugCommands(argv, appContext.db, config());
// if (done) {
// appLogger().info('Debug command has been executed. Now starting server...');
// }
// }
appLogger().info(`Call this for testing: \`curl ${config().apiBaseUrl}/api/ping\``); appLogger().info(`Call this for testing: \`curl ${config().apiBaseUrl}/api/ping\``);
// const tree: any = {
// '000000000000000000000000000000F1': {},
// '000000000000000000000000000000F2': {
// '00000000000000000000000000000001': null,
// '00000000000000000000000000000002': null,
// },
// '000000000000000000000000000000F3': {
// '00000000000000000000000000000003': null,
// '000000000000000000000000000000F4': {
// '00000000000000000000000000000004': null,
// '00000000000000000000000000000005': null,
// },
// },
// '00000000000000000000000000000006': null,
// '00000000000000000000000000000007': null,
// };
// const users = await appContext.models.user().all();
// const itemModel = appContext.models.item({ userId: users[0].id });
// await createItemTree(itemModel, '', tree);
app.listen(config().port); app.listen(config().port);
} }
} }

View File

@ -1,6 +1,7 @@
import { rtrimSlashes } from '@joplin/lib/path-utils'; import { rtrimSlashes } from '@joplin/lib/path-utils';
import { Config, DatabaseConfig, DatabaseConfigClient, MailerConfig, RouteType } from './utils/types'; import { Config, DatabaseConfig, DatabaseConfigClient, MailerConfig, RouteType } from './utils/types';
import * as pathUtils from 'path'; import * as pathUtils from 'path';
import { readFile } from 'fs-extra';
export interface EnvVariables { export interface EnvVariables {
APP_BASE_URL?: string; APP_BASE_URL?: string;
@ -91,17 +92,31 @@ function baseUrlFromEnv(env: any, appPort: number): string {
} }
} }
interface PackageJson {
version: string;
}
async function readPackageJson(filePath: string): Promise<PackageJson> {
const text = await readFile(filePath, 'utf8');
return JSON.parse(text);
}
let config_: Config = null; let config_: Config = null;
export function initConfig(env: EnvVariables, overrides: any = null) { export async function initConfig(env: EnvVariables, overrides: any = null) {
runningInDocker_ = !!env.RUNNING_IN_DOCKER; runningInDocker_ = !!env.RUNNING_IN_DOCKER;
const rootDir = pathUtils.dirname(__dirname); const rootDir = pathUtils.dirname(__dirname);
const viewDir = `${pathUtils.dirname(__dirname)}/src/views`;
const packageJson = await readPackageJson(`${rootDir}/package.json`);
const viewDir = `${rootDir}/src/views`;
const appPort = env.APP_PORT ? Number(env.APP_PORT) : 22300; const appPort = env.APP_PORT ? Number(env.APP_PORT) : 22300;
const baseUrl = baseUrlFromEnv(env, appPort); const baseUrl = baseUrlFromEnv(env, appPort);
config_ = { config_ = {
appVersion: packageJson.version,
appName: 'Joplin Server',
rootDir: rootDir, rootDir: rootDir,
viewDir: viewDir, viewDir: viewDir,
layoutDir: `${viewDir}/layouts`, layoutDir: `${viewDir}/layouts`,

View File

@ -27,6 +27,8 @@ interface GlobalParams {
notifications?: NotificationView[]; notifications?: NotificationView[];
hasNotifications?: boolean; hasNotifications?: boolean;
owner?: User; owner?: User;
appVersion?: string;
appName?: string;
} }
export function isView(o: any): boolean { export function isView(o: any): boolean {
@ -76,6 +78,8 @@ export default class MustacheService {
return { return {
baseUrl: config().baseUrl, baseUrl: config().baseUrl,
prefersDarkEnabled: this.prefersDarkEnabled_, prefersDarkEnabled: this.prefersDarkEnabled_,
appVersion: config().appVersion,
appName: config().appName,
}; };
} }

View File

@ -66,7 +66,7 @@ export async function beforeAllDb(unitName: string) {
// Uncomment the code below to run the test units with Postgres. Run first // Uncomment the code below to run the test units with Postgres. Run first
// `docker-compose -f docker-compose.db-dev.yml` to get a dev db. // `docker-compose -f docker-compose.db-dev.yml` to get a dev db.
// initConfig({ // await initConfig({
// DB_CLIENT: 'pg', // DB_CLIENT: 'pg',
// POSTGRES_DATABASE: unitName, // POSTGRES_DATABASE: unitName,
// POSTGRES_USER: 'joplin', // POSTGRES_USER: 'joplin',
@ -75,7 +75,7 @@ export async function beforeAllDb(unitName: string) {
// tempDir: tempDir, // tempDir: tempDir,
// }); // });
initConfig({ await initConfig({
SQLITE_DATABASE: createdDbPath_, SQLITE_DATABASE: createdDbPath_,
}, { }, {
tempDir: tempDir, tempDir: tempDir,

View File

@ -58,6 +58,8 @@ export interface MailerConfig {
} }
export interface Config { export interface Config {
appVersion: string;
appName: string;
port: number; port: number;
rootDir: string; rootDir: string;
viewDir: string; viewDir: string;

View File

@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" href="{{{global.baseUrl}}}/css/bulma.min.css" crossorigin="anonymous"> <link rel="stylesheet" href="{{{global.baseUrl}}}/css/bulma.min.css" crossorigin="anonymous">
{{#global.prefersDarkEnabled}} {{#global.prefersDarkEnabled}}
<link rel="stylesheet" href="{{{global.baseUrl}}}/css/bulma-prefers-dark.min.css" crossorigin="anonymous"> <!-- <link rel="stylesheet" href="{{{global.baseUrl}}}/css/bulma-prefers-dark.min.css" crossorigin="anonymous"> -->
{{/global.prefersDarkEnabled}} {{/global.prefersDarkEnabled}}
<link rel="stylesheet" href="{{{global.baseUrl}}}/css/main.css" crossorigin="anonymous"> <link rel="stylesheet" href="{{{global.baseUrl}}}/css/main.css" crossorigin="anonymous">
<link rel="stylesheet" href="{{{global.baseUrl}}}/css/fontawesome/css/all.min.css" crossorigin="anonymous"> <link rel="stylesheet" href="{{{global.baseUrl}}}/css/fontawesome/css/all.min.css" crossorigin="anonymous">
@ -19,8 +19,11 @@
<body class="page-{{{pageName}}}"> <body class="page-{{{pageName}}}">
{{> navbar}} {{> navbar}}
<main class="main"> <main class="main">
<div class="container">
{{> notifications}} {{> notifications}}
{{{contentHtml}}} {{{contentHtml}}}
</div>
</main> </main>
{{> footer}}
</body> </body>
</html> </html>

View File

@ -0,0 +1,5 @@
<div class="footer">
<div class="container">
{{global.appName}} {{global.appVersion}}
</div>
</div>

View File

@ -1,5 +1,6 @@
{{#navbar}} {{#navbar}}
<nav class="navbar" role="navigation" aria-label="main navigation"> <nav class="navbar is-dark" role="navigation" aria-label="main navigation">
<div class="container">
<div class="navbar-brand logo-container"> <div class="navbar-brand logo-container">
<a class="navbar-item" href="{{{global.baseUrl}}}/home"> <a class="navbar-item" href="{{{global.baseUrl}}}/home">
<img class="logo" src="{{{global.baseUrl}}}/images/Logo.png"/> <img class="logo" src="{{{global.baseUrl}}}/images/Logo.png"/>
@ -24,5 +25,6 @@
</div> </div>
</div> </div>
</div> </div>
</div>
</nav> </nav>
{{/navbar}} {{/navbar}}