Skip to content

Commit 9f010f4

Browse files
author
Raymond Ottun
committed
fix: display configs
1 parent d1499f8 commit 9f010f4

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,5 @@ jobs:
133133
region: europe-west2
134134
env_vars: |
135135
MIMIC_PORT=8080
136-
MIMIC_MOCKS_DIRECTORY=/prefabs/shopfiy/mocks
137-
MIMIC_PARTIALS_DIRECTORY=/prefabs/shopfiy/partials
136+
MIMIC_MOCKS_DIRECTORY=/app/prefabs/shopfiy/mocks
137+
MIMIC_PARTIALS_DIRECTORY=/app/prefabs/shopfiy/partials

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ADD server .
1818

1919
# Compile the main app so that it doesn't need to be compiled each startup/entry.
2020
COPY --from=build-ui /app/dist /app/dashboard
21-
COPY prefabs /prefabs
21+
COPY prefabs /app/
2222

2323
RUN deno compile --allow-sys \
2424
--allow-net \

server/src/handlers/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import Engine from '../engine.ts';
22
import { createHandler as createMocksHandler } from './mocks.ts';
33
import { createHandler as createAPIHandler } from './api.ts';
44
import { createHandler as createDashboardHandler } from './dashboard.ts';
5-
import { logger } from '../deps.ts';
5+
import { logger, MimicConfig } from '../deps.ts';
66

77
export interface HandlerOptions {
88
engine: Engine;
99
cors?: boolean;
10+
config: MimicConfig;
1011
}
1112

1213
export const createHandlers = (opts: HandlerOptions) => {
@@ -32,8 +33,8 @@ export const createHandlers = (opts: HandlerOptions) => {
3233
return new Response();
3334
}
3435

35-
else if (url.pathname.includes('status')) {
36-
return new Response('ok')
36+
if (url.pathname.includes('status')) {
37+
return new Response('ok');
3738
}
3839

3940
if (url.pathname.startsWith('/_/api')) {
@@ -44,6 +45,15 @@ export const createHandlers = (opts: HandlerOptions) => {
4445
return dashboardHandler(request);
4546
}
4647

48+
if (url.pathname.startsWith('/_/config')) {
49+
return new Response(JSON.stringify(opts.config), {
50+
status: 200,
51+
headers: {
52+
'content-type': 'application/json',
53+
},
54+
});
55+
}
56+
4757
logger.info(`${request.method} - ${request.url}`);
4858
return mockHandler(request);
4959
};

server/src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { logger, MimicConfig, parse } from './deps.ts';
2-
import { startServers } from './start.ts';
2+
import { startServer } from './start.ts';
33

44
const flags = parse(Deno.args);
55

@@ -36,7 +36,7 @@ const config: MimicConfig = {
3636
};
3737

3838
logger.info('**** Mimic Server ****');
39-
startServers(config);
39+
startServer(config);
4040

4141
Deno.addSignalListener('SIGINT', () => {
4242
logger.info('Exited');

server/src/start.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ const defaultConfig = {
99
mocksDirectory: 'mocks',
1010
};
1111

12-
export const startServers = async (config: MimicConfig) => {
12+
export const startServer = async (config: MimicConfig) => {
1313
const fullConfig = Object.assign({}, defaultConfig, config);
1414
const { tlsCertFile, tlsKeyFile, port } = fullConfig;
1515
const engine = await createMemoryEngine(
1616
fullConfig,
1717
fullConfig.mocksDirectory,
1818
);
19-
const requestHandler = createHandlers({ engine, cors: true });
19+
const requestHandler = createHandlers({ engine, cors: true, config });
2020
const wsHandler = createWsHandler({ storage: engine.storage });
2121

2222
await registerPartials(fullConfig.partialsDirectory);

server/src/storages/memory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export class MemoryStorage implements RecordStorage {
112112
const mocks: any[] = [];
113113
try {
114114
if (!fs.existsSync(mocksDirectory)) {
115+
logger.warning(`${mocksDirectory} not found. No mocks loaded`);
115116
return Promise.resolve([]);
116117
}
117118

0 commit comments

Comments
 (0)