Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions developer/src/server/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
* Environmental variables and paths
*/
import path from 'node:path';
import { extractVersionData } from './version-data.js';
// TODO: environment should be just KEYMAN_VERSION

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the trigger for this PR


import KEYMAN_VERSION from "@keymanapp/keyman-version";
export const environment = extractVersionData(KEYMAN_VERSION.VERSION_WITH_TAG);

/**
* @returns base path for the running server -- where index.js is stored
Expand Down
14 changes: 10 additions & 4 deletions developer/src/server/src/handlers/inc/packages-json.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { KeymanUrls } from '@keymanapp/developer-utils';
/*
* Keyman is copyright (C) SIL Global. MIT License.
*
* API: return list of packages under testing and urls for installing in mobile
* apps
*/
import * as express from 'express';
import { KeymanUrls } from '@keymanapp/developer-utils';
import KEYMAN_VERSION from '@keymanapp/keyman-version';
import { data } from "../../data.js";
import { environment } from '../../environment.js';

export default function handleIncPackagesJson (req: express.Request, res: express.Response) {
const packages = Object.keys(data.packages).map(id => { return { id: id, filename: id+'.kmp', name: data.packages[id].name} });
res.send({
packages: packages,
urls: {
installLinkAndroid: KeymanUrls.KeymanDeveloper_KeymanForAndroidDownload(environment.versionRelease),
installLinkIos: KeymanUrls.KeymanDeveloper_KeymanForIosDownload(environment.versionRelease),
installLinkAndroid: KeymanUrls.KeymanDeveloper_KeymanForAndroidDownload(KEYMAN_VERSION.VERSION_RELEASE),
installLinkIos: KeymanUrls.KeymanDeveloper_KeymanForIosDownload(KEYMAN_VERSION.VERSION_RELEASE),
}
});
}
11 changes: 8 additions & 3 deletions developer/src/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/*
* Keyman is copyright (C) SIL Global. MIT License.
*
* Keyman Developer Server main program
*/
import * as fs from 'node:fs';
import * as path from 'node:path';
import chalk from 'chalk';
import express from 'express';
import multer from 'multer';
import * as ws from 'ws';
import KEYMAN_VERSION from '@keymanapp/keyman-version';
import { KeymanSentry } from './KeymanSentry.js';
import { standardPaths } from './standardPaths.js';
import { environment } from './environment.js';
import setupRoutes from './routes.js';
import { shutdown } from './shutdown.js';
import { initTray } from './tray.js';
Expand All @@ -23,7 +28,7 @@ const options = {
// set of options if an error occurs.
await loadOptions();

console.log(`Starting Keyman Developer Server ${environment.versionWithTag}, listening on port ${getOption('web host port')}.`);
console.log(`Starting Keyman Developer Server ${KEYMAN_VERSION.VERSION_WITH_TAG}, listening on port ${getOption('web host port')}.`);

KeymanSentry.init();
try {
Expand Down Expand Up @@ -74,7 +79,7 @@ export async function run() {

/* Setup routes */

setupRoutes(app, upload, wsServer, environment);
setupRoutes(app, upload, wsServer);

/* Start the web server */

Expand Down
10 changes: 4 additions & 6 deletions developer/src/server/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as express from 'express';
import * as ws from 'ws';
import * as multer from 'multer';
import KEYMAN_VERSION from '@keymanapp/keyman-version';
import handleIncKeyboardsJs from './handlers/inc/keyboards-js.js';
import { data, DebugFont, DebugKeyboard, DebugModel, DebugObject, DebugPackage, isValidId } from './data.js';
import apiGet from './handlers/api/debugobject/get.js';
Expand All @@ -16,23 +17,20 @@ import apiUnregister from './handlers/api/debugobject/unregister.js';
import handleIncPackagesJson from './handlers/inc/packages-json.js';
import apiPackageRegister from './handlers/api/package/register.js';
import handleIncKeyboardsCss from './handlers/inc/keyboards-css.js';
import { Environment } from './version-data.js';
import { standardPaths } from './standardPaths.js';
import chalk from 'chalk';
import { shutdown } from './shutdown.js';
import { getOption } from './options.js';
import { serverSitePath } from './environment.js';

export default function setupRoutes(app: express.Express, upload: multer.Multer, wsServer: ws.WebSocketServer, environment: Environment ) {
export default function setupRoutes(app: express.Express, upload: multer.Multer, wsServer: ws.WebSocketServer ) {

/* Middleware - JSON and logging */

app.use(express.json()); // for parsing application/json

app.use(function (req, _res, next) {
// if(environment.environment == 'local') {
console.log(req.method + ' ' + req.path);
// }
console.log(req.method + ' ' + req.path);
next();
});

Expand Down Expand Up @@ -99,7 +97,7 @@ export default function setupRoutes(app: express.Express, upload: multer.Multer,
app.get('/inc/packages.json', handleIncPackagesJson);

app.get('/api-public/version', (req,res,next)=>{
res.json({version: environment.versionWithTag, isApiAvailable: isLocalhost(req)});
res.json({version: KEYMAN_VERSION.VERSION_WITH_TAG, isApiAvailable: isLocalhost(req)});
next();
});

Expand Down
52 changes: 0 additions & 52 deletions developer/src/server/src/version-data.ts

This file was deleted.

20 changes: 20 additions & 0 deletions developer/src/server/test/environment.tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Keyman is copyright (C) SIL Global. MIT License.
*/
import * as fs from 'node:fs';
import * as path from 'node:path';
import {assert} from 'chai';
import 'mocha';
import { serverBasePath, serverSitePath } from '../src/environment.js';

describe('serverBasePath', function() {
it('should find index.js in the base path', function() {
assert.isTrue(fs.existsSync(path.join(serverBasePath(), 'index.js')));
});
});

describe('serverSitePath', function() {
it('should find index.html in the base path', function() {
assert.isTrue(fs.existsSync(path.join(serverSitePath(), 'index.html')));
});
});
55 changes: 0 additions & 55 deletions developer/src/server/test/version-data.tests.ts

This file was deleted.