use proxy and router prefix config in server

This commit is contained in:
Alexandre Bodin 2021-09-02 10:40:16 +02:00
parent ae8c970661
commit 58dde6837f
6 changed files with 26 additions and 26 deletions

View File

@ -52,15 +52,13 @@ describe('Admin Controller', () => {
describe('information', () => {
beforeAll(() => {
global.strapi = {
app: {
env: 'development',
},
config: {
get: jest.fn(
(key, value) =>
({
autoReload: undefined,
'info.strapi': '1.0.0',
environment: 'development',
}[key] || value)
),
},
@ -71,7 +69,11 @@ describe('Admin Controller', () => {
test('Returns application information', async () => {
const result = await adminController.information();
expect(global.strapi.config.get).toHaveBeenCalledTimes(2);
expect(global.strapi.config.get.mock.calls).toEqual([
['environment'],
['autoReload', false],
['info.strapi', null],
]);
expect(result.data).toBeDefined();
expect(result.data).toStrictEqual({
currentEnvironment: 'development',

View File

@ -17,8 +17,8 @@ const pluginsRegistry = strapi => {
throw new Error(`Plugin ${name} has already been registered.`);
}
const moduleInstance = strapi.container.get('modules').add(`plugin::${name}`, pluginConfig);
plugins[name] = moduleInstance;
const pluginModule = strapi.container.get('modules').add(`plugin::${name}`, pluginConfig);
plugins[name] = pluginModule;
return plugins[name];
},

View File

@ -27,9 +27,12 @@ describe('Session middleware', () => {
);
const mockStrapi = {
app: {
server: {
app: {
use: jest.fn(),
context: {},
},
use: jest.fn(),
context: {},
},
config: {
appPath: __dirname,

View File

@ -6,7 +6,7 @@ const Router = require('@koa/router');
const { createHTTPServer } = require('./http-server');
const createEndpointComposer = require('./middlewares/router/utils/compose-endpoint');
const createEndpointComposer = require('./utils/compose-endpoint');
const createRouteManager = strapi => {
const composeEndpoint = createEndpointComposer(strapi);
@ -80,13 +80,14 @@ const healthCheck = async (ctx, next) => {
* @returns {Server}
*/
const createServer = strapi => {
// TODO: set root level prefix
// strapi.router.prefix(strapi.config.get('middleware.settings.router.prefix', ''));
const app = new Koa({
proxy: strapi.config.get('server.proxy'),
});
const app = new Koa();
const router = new Router();
app.proxy = strapi.config.get('server.proxy');
const router = new Router({
// FIXME: this prefix can break the admin if not specified in the admin url
prefix: strapi.config.get('middleware.settings.router.prefix', ''),
});
const routeManager = createRouteManager(strapi);
@ -94,7 +95,7 @@ const createServer = strapi => {
const apis = {
admin: createAPI(strapi, { prefix: '/admin' }),
// set prefix to api
// TODO: set prefix to api
'content-api': createAPI(strapi),
};
@ -113,12 +114,6 @@ const createServer = strapi => {
return apis[name];
},
/**
* Add a middleware to the main koa app or an api
* @param {string|function} path
* @param {function} fn
* @returns {Server}
*/
use(path, fn) {
if (typeof path === 'function') {
app.use(path);

View File

@ -21,7 +21,7 @@ describe('metrics', () => {
strapi: '0.0.0',
},
},
app: {
server: {
use,
},
});
@ -43,7 +43,7 @@ describe('metrics', () => {
strapi: '0.0.0',
},
},
app: {
server: {
use,
},
});
@ -63,7 +63,7 @@ describe('metrics', () => {
strapi: '0.0.0',
},
},
app: {
server: {
use() {},
},
});
@ -96,7 +96,7 @@ describe('metrics', () => {
strapi: '0.0.0',
},
},
app: {
server: {
use() {},
},
});