Skip to content
Open
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ typings/
.store

# Ignore OSX crap-files
*.DS_Store
*.DS_Store
app/dist/
dist/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"jest.rootPath": "app"
}
26 changes: 18 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@ RUN mkdir /store
# Add useful stuff
RUN apk add --no-cache tzdata openssl curl git jq bash

# Dependencies stage
FROM base AS dependencies
# Dependencies stage (Build)
FROM base AS build

# Copy app package.json
COPY app/package* ./

# Install dependencies
RUN npm ci --omit=dev --omit=optional --no-audit --no-fund --no-update-notifier
# Install dependencies (including dev)
RUN npm ci --include=dev --omit=optional --no-audit --no-fund --no-update-notifier

# Copy app source
COPY app/ ./

# Build
RUN npm run build

# Remove dev dependencies
RUN npm prune --omit=dev

# Release stage
FROM base AS release
Expand All @@ -35,13 +44,14 @@ FROM base AS release
COPY Docker.entrypoint.sh /usr/bin/entrypoint.sh
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
CMD ["node", "index"]
CMD ["node", "dist/index"]

## Copy node_modules
COPY --from=dependencies /home/node/app/node_modules ./node_modules
COPY --from=build /home/node/app/node_modules ./node_modules

# Copy app
COPY app/ ./
# Copy app (dist)
COPY --from=build /home/node/app/dist ./dist
COPY --from=build /home/node/app/package.json ./package.json

# Copy ui
COPY ui/dist/ ./ui
3 changes: 0 additions & 3 deletions app/.babelrc

This file was deleted.

31 changes: 16 additions & 15 deletions app/api/api.test.js → app/api/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
// Mock all the router modules
jest.mock('express', () => ({
Router: jest.fn(() => ({
Expand Down Expand Up @@ -42,30 +43,30 @@ jest.mock('passport', () => ({
authenticate: jest.fn(() => (req, res, next) => next()),
}));

const api = require('./api');
import * as api from './api';

describe('API Router', () => {
let router;

beforeEach(() => {
beforeEach(async () => {
jest.clearAllMocks();
router = api.init();
});

test('should initialize and return a router', () => {
test('should initialize and return a router', async () => {
expect(router).toBeDefined();
});

test('should mount all sub-routers', () => {
const appRouter = require('./app');
const containerRouter = require('./container');
const watcherRouter = require('./watcher');
const triggerRouter = require('./trigger');
const registryRouter = require('./registry');
const authenticationRouter = require('./authentication');
const logRouter = require('./log');
const storeRouter = require('./store');
const serverRouter = require('./server');
test('should mount all sub-routers', async () => {
const appRouter = await import('./app');
const containerRouter = await import('./container');
const watcherRouter = await import('./watcher');
const triggerRouter = await import('./trigger');
const registryRouter = await import('./registry');
const authenticationRouter = await import('./authentication');
const logRouter = await import('./log');
const storeRouter = await import('./store');
const serverRouter = await import('./server');

expect(appRouter.init).toHaveBeenCalled();
expect(containerRouter.init).toHaveBeenCalled();
Expand All @@ -78,8 +79,8 @@ describe('API Router', () => {
expect(serverRouter.init).toHaveBeenCalled();
});

test('should use passport authentication middleware', () => {
const passport = require('passport');
test('should use passport authentication middleware', async () => {
const passport = await import('passport');
expect(passport.authenticate).toHaveBeenCalledWith([
'basic',
'anonymous',
Expand Down
31 changes: 14 additions & 17 deletions app/api/api.js → app/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
const express = require('express');
const passport = require('passport');
const appRouter = require('./app');
const containerRouter = require('./container');
const watcherRouter = require('./watcher');
const triggerRouter = require('./trigger');
const registryRouter = require('./registry');
const authenticationRouter = require('./authentication');
const logRouter = require('./log');
const storeRouter = require('./store');
const serverRouter = require('./server');
const auth = require('./auth');
// @ts-nocheck
import express from 'express';
import passport from 'passport';
import * as appRouter from './app';
import * as containerRouter from './container';
import * as watcherRouter from './watcher';
import * as triggerRouter from './trigger';
import * as registryRouter from './registry';
import * as authenticationRouter from './authentication';
import * as logRouter from './log';
import * as storeRouter from './store';
import * as serverRouter from './server';
import * as auth from './auth';

/**
* Init the API router.
* @returns {*|Router}
*/
function init() {
export function init() {
const router = express.Router();

// Mount app router
Expand Down Expand Up @@ -53,7 +54,3 @@ function init() {

return router;
}

module.exports = {
init,
};
11 changes: 6 additions & 5 deletions app/api/app.test.js → app/api/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
// Mock the store module
jest.mock('../store/app', () => ({
getAppInfos: jest.fn(() => ({
Expand All @@ -17,23 +18,23 @@ jest.mock('express', () => ({

jest.mock('nocache', () => jest.fn());

const appRouter = require('./app');
import * as appRouter from './app';

describe('App Router', () => {
beforeEach(() => {
beforeEach(async () => {
jest.clearAllMocks();
});

test('should initialize router with nocache and route', () => {
test('should initialize router with nocache and route', async () => {
const router = appRouter.init();

expect(router).toBeDefined();
expect(router.use).toHaveBeenCalled();
expect(router.get).toHaveBeenCalledWith('/', expect.any(Function));
});

test('should call getAppInfos when route handler is called', () => {
const storeApp = require('../store/app');
test('should call getAppInfos when route handler is called', async () => {
const storeApp = await import('../store/app');
const router = appRouter.init();

// Get the route handler function
Expand Down
13 changes: 5 additions & 8 deletions app/api/app.js → app/api/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express');
const nocache = require('nocache');
const storeApp = require('../store/app');
// @ts-nocheck
import express from 'express';
import nocache from 'nocache';
import * as storeApp from '../store/app';

/**
* App infos router.
Expand All @@ -20,12 +21,8 @@ function getAppInfos(req, res) {
* Init Router.
* @returns {*}
*/
function init() {
export function init() {
router.use(nocache());
router.get('/', getAppInfos);
return router;
}

module.exports = {
init,
};
31 changes: 14 additions & 17 deletions app/api/auth.js → app/api/auth.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const express = require('express');
const session = require('express-session');
const LokiStore = require('connect-loki')(session);
const passport = require('passport');
const { v5: uuidV5 } = require('uuid');
const getmac = require('getmac').default;
const store = require('../store');
const registry = require('../registry');
const log = require('../log');
const { getVersion } = require('../configuration');
// @ts-nocheck
import express from 'express';
import session from 'express-session';
import ConnectLoki from 'connect-loki';
const LokiStore = ConnectLoki(session);
import passport from 'passport';
import { v5 as uuidV5 } from 'uuid';
import getmac from 'getmac';
import * as store from '../store';
import * as registry from '../registry';
import log from '../log';
import { getVersion } from '../configuration';

const router = express.Router();

Expand All @@ -21,7 +23,7 @@ const WUD_NAMESPACE = 'dee41e92-5fc4-460e-beec-528c9ea7d760';
* Get all strategies id.
* @returns {[]}
*/
function getAllIds() {
export function getAllIds() {
return STRATEGY_IDS;
}

Expand Down Expand Up @@ -132,7 +134,7 @@ function logout(req, res) {
* Init auth (passport.js).
* @returns {*}
*/
function init(app) {
export function init(app) {
// Init express session
app.use(
session({
Expand Down Expand Up @@ -182,8 +184,3 @@ function init(app) {

app.use('/auth', router);
}

module.exports = {
init,
getAllIds,
};
13 changes: 0 additions & 13 deletions app/api/authentication.js

This file was deleted.

10 changes: 10 additions & 0 deletions app/api/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-nocheck
import * as component from './component';

/**
* Init Router.
* @returns {*}
*/
export function init() {
return component.init('authentication');
}
21 changes: 8 additions & 13 deletions app/api/component.js → app/api/component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { byValues, byString } = require('sort-es');
// @ts-nocheck
import { byValues, byString } from 'sort-es';

const express = require('express');
const nocache = require('nocache');
const registry = require('../registry');
import express from 'express';
import nocache from 'nocache';
import * as registry from '../registry';

/**
* Map a Component to a displayable (api/ui) item.
Expand All @@ -24,7 +25,7 @@ function mapComponentToItem(key, component) {
* @param listFunction
* @returns {{id: string}[]}
*/
function mapComponentsToList(components) {
export function mapComponentsToList(components) {
return Object.keys(components)
.map((key) => mapComponentToItem(key, components[key]))
.sort(
Expand All @@ -50,7 +51,7 @@ function getAll(req, res, kind) {
* @param res
* @param listFunction
*/
function getById(req, res, kind) {
export function getById(req, res, kind) {
const { type, name } = req.params;
const id = `${type}.${name}`;
const component = registry.getState()[kind][id];
Expand All @@ -66,16 +67,10 @@ function getById(req, res, kind) {
* @param kind
* @returns {*|Router}
*/
function init(kind) {
export function init(kind) {
const router = express.Router();
router.use(nocache());
router.get('/', (req, res) => getAll(req, res, kind));
router.get('/:type/:name', (req, res) => getById(req, res, kind));
return router;
}

module.exports = {
init,
mapComponentsToList,
getById,
};
Loading