Skip to content

Commit

Permalink
fix: separate public url and mount path in main.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
bmestanov committed Mar 9, 2022
1 parent b155172 commit bf79a5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ Required version of MongoDB: >2.6.0

Agenda Admin can be used as express middleware, using the `mountAgendaAdmin` function. As an argument, it takes an object with the following fields:

- `publicUrl` - the URL at which the the middleware should be mounted
- `publicUrl` - the URL at which the frontend is served
- `mountPath` - the path which the middleware should be mounted (passed to `app.use()`)
- `expressApp` - the express app
- `agenda` - an agenda instance
- `options` - an optional argument, the object can have the following properties:
- `options` - an optional argument, the object can have the following properties:
- `itemsPerPage`
- `username`
- `password`
- `password`

#### Example:

Expand Down
16 changes: 8 additions & 8 deletions api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { OptionsType, setOptions } from 'src/options';

import Agenda from 'agenda';
import { Express } from 'express';
import app from 'src/app';
import fs from 'fs-extra';
import path from 'path';
import replaceStream from 'replacestream';
import Agenda from 'agenda';
import { URL } from 'url';
import { Express } from 'express';
import { setAgendaInstance } from 'src/agenda-instance';
import app from 'src/app';
import { OptionsType, setOptions } from 'src/options';

export interface ParamsType {
publicUrl: string;
mountPath: string;
expressApp: Express;
agenda: Agenda;
options?: OptionsType;
}

export const mountAgendaAdmin = async ({
publicUrl,
mountPath,
expressApp,
agenda,
options,
}: ParamsType) => {
const parsedUrl = new URL(publicUrl);

await fs.copy(
path.join(__dirname, '../client'),
path.join(__dirname, '../public')
Expand Down Expand Up @@ -61,5 +61,5 @@ export const mountAgendaAdmin = async ({

setAgendaInstance(agenda);
setOptions(options);
expressApp.use(parsedUrl.pathname, app);
expressApp.use(mountPath, app);
};

0 comments on commit bf79a5a

Please sign in to comment.