2021-10-29 10:33:05 -05:00
|
|
|
import bodyParser from 'body-parser';
|
2021-03-06 12:56:45 -05:00
|
|
|
import express from 'express';
|
|
|
|
import { Application } from 'express';
|
2021-10-29 10:33:05 -05:00
|
|
|
import path from 'path';
|
2021-03-06 12:56:45 -05:00
|
|
|
|
|
|
|
import { Auth, IAuth } from '@verdaccio/auth';
|
2021-10-29 10:33:05 -05:00
|
|
|
import { Config, parseConfigFile } from '@verdaccio/config';
|
2021-03-06 12:56:45 -05:00
|
|
|
import { setup } from '@verdaccio/logger';
|
2021-10-29 10:33:05 -05:00
|
|
|
import { errorReportingMiddleware, final, handleError } from '@verdaccio/middleware';
|
|
|
|
import { Storage } from '@verdaccio/store';
|
|
|
|
|
2021-03-06 12:56:45 -05:00
|
|
|
import routes from '../src';
|
|
|
|
|
|
|
|
setup([]);
|
|
|
|
|
|
|
|
const getConf = (configName: string) => {
|
|
|
|
const configPath = path.join(__dirname, 'config', configName);
|
|
|
|
return parseConfigFile(configPath);
|
|
|
|
};
|
|
|
|
|
|
|
|
export async function initializeServer(configName: string): Promise<Application> {
|
|
|
|
const app = express();
|
|
|
|
const config = new Config(getConf(configName));
|
2021-11-05 10:29:48 -05:00
|
|
|
config.checkSecretKey('12345');
|
2021-03-06 12:56:45 -05:00
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config, []);
|
|
|
|
const auth: IAuth = new Auth(config);
|
|
|
|
// for parsing the body (login api)
|
|
|
|
app.use(bodyParser.json({ strict: false, limit: '10mb' }));
|
|
|
|
// @ts-ignore
|
|
|
|
app.use(errorReportingMiddleware);
|
|
|
|
app.use(routes(config, auth, storage));
|
|
|
|
// @ts-ignore
|
|
|
|
app.use(handleError);
|
|
|
|
// @ts-ignore
|
|
|
|
app.use(final);
|
|
|
|
return app;
|
|
|
|
}
|