Skip to content

Commit

Permalink
2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarbounakis committed Mar 31, 2024
1 parent caef503 commit a69f6ee
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 204 deletions.
4 changes: 2 additions & 2 deletions modules/test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion modules/test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@themost/test",
"version": "2.3.4",
"version": "2.4.0",
"description": "MOST Web Framework Test Api Server",
"repository": "https://github.com/themost-framework/themost-test.git",
"author": "Kyriakos Barbounakis<k.barbounakis@gmail.com>",
Expand Down
41 changes: 21 additions & 20 deletions modules/test/server/app.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@

import express from 'express';
import {ViewEngine} from '@themost/ejs';
import { ViewEngine } from '@themost/ejs';
import path from 'path';
import passport from 'passport';
import {authRouter} from './routes/auth';
import { authRouter } from './routes/auth';
// eslint-disable-next-line no-unused-vars
import { ExpressDataApplication, serviceRouter, dateReviver, ExpressDataContext } from '@themost/express';
import {indexRouter} from './routes/index';
import { ExpressDataApplication, serviceRouter, getMetadataDocument, dateReviver, ExpressDataContext } from '@themost/express';
import { indexRouter } from './routes/index';
import temp from 'temp';
import fs from 'fs';
import cors from 'cors';
import { Authenticator } from './routes/auth';
import { docsRouter } from './routes/docs';
import createError from 'http-errors';
import {HttpUnauthorizedError} from '@themost/common';
import { HttpUnauthorizedError } from '@themost/common';

function getApplication() {
const config = require('./config/app.json');
// prepare temp database
const findAdapter = config.adapters.find( adapter => {
// prepare temp database
const findAdapter = config.adapters.find(adapter => {
return adapter.name === 'test';
});
let testDatabase;
Expand Down Expand Up @@ -47,14 +47,14 @@ function getApplication() {
*/
let app = express();

// enable CORS
app.use(cors({ origin:true, credentials: true }));
// enable CORS
app.use(cors({ origin: true, credentials: true }));

app.use('/assets', express.static(path.join(__dirname, 'assets')))
app.use('/assets', express.static(path.join(__dirname, 'assets')))

// use ViewEngine for all ejs templates
// use ViewEngine for all ejs templates
app.engine('ejs', ViewEngine.express());
// view engine setup
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

Expand All @@ -63,17 +63,17 @@ app.use('/assets', express.static(path.join(__dirname, 'assets')))
}));
app.use(express.urlencoded({ extended: true }));

// @themost/data data application setup
// @themost/data data application setup
const dataApplication = new ExpressDataApplication(path.resolve(__dirname, 'config'));

if (dataApplication.hasService(Authenticator) === false) {
dataApplication.useService(Authenticator);
}

// hold data application
// hold data application
app.set('ExpressDataApplication', dataApplication);

// use data middleware (register req.context)
// use data middleware (register req.context)
app.use(dataApplication.middleware());

app.use('/', indexRouter);
Expand All @@ -83,8 +83,9 @@ app.use('/assets', express.static(path.join(__dirname, 'assets')))

app.use('/api/docs', docsRouter);

// use @themost/express service router
// noinspection JSCheckFunctionSignatures
app.get('/api/\\$metadata', getMetadataDocument());
// use @themost/express service router
// noinspection JSCheckFunctionSignatures
app.use('/api/', (req, res, next) => {
passport.authenticate('bearer', { session: false }, (err, user) => {
if (err) { return next(err); }
Expand All @@ -96,11 +97,11 @@ app.use('/assets', express.static(path.join(__dirname, 'assets')))
})(req, res, next);
}, serviceRouter);

// catch 404 and forward to error handler
// catch 404 and forward to error handler
app.use((_req, _res, next) => {
next(createError(404));
});
// error handler
// error handler
app.use((err, req, res, next) => {
if (res.headersSent) {
return next(err)
Expand Down Expand Up @@ -146,4 +147,4 @@ app.use('/assets', express.static(path.join(__dirname, 'assets')))
return app;
}

export {getApplication};
export { getApplication };
Loading

0 comments on commit a69f6ee

Please sign in to comment.