Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function givenRunningApplicationWithCustomConfiguration() {
app = new TodoListApplication({
rest: givenHttpServerConfig(),
});
await app.boot();
/**
* Override default config for DataSource for testing so we don't write
* test data to file when using the memory connector.
*/
app.bind('datasources.config.db').to({
name: 'db',
connector: 'memory',
});
// Start Application
await app.start();
}
export async function setupApplication(): Promise {
const restConfig = givenHttpServerConfig({
// Customize the server configuration here.
// Empty values (undefined, '') will be ignored by the helper.
//
// host: process.env.HOST,
// port: +process.env.PORT,
});
const app = new Lb4JwtRoleBasedAuthSampleApplication({
rest: restConfig,
});
await app.boot();
await app.start();
const client = createRestAppClient(app);
it('starts server', async () => {
const serverOptions = givenHttpServerConfig();
server = new HttpServer(dummyRequestHandler, serverOptions);
await server.start();
await supertest(server.url)
.get('/')
.expect(200);
});
it('supports HTTPS protocol with key and certificate files', async () => {
const keyPath = path.join(FIXTURES, 'key.pem');
const certPath = path.join(FIXTURES, 'cert.pem');
const serverOptions = givenHttpServerConfig({
port: 0,
protocol: 'https',
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
});
const server = await givenAServer({rest: serverOptions});
server.handler(dummyRequestHandler);
await server.start();
const serverUrl = server.getSync(RestBindings.URL);
const res = await httpsGetAsync(serverUrl);
expect(res.statusCode).to.equal(200);
});
function givenAnApplication() {
app = new HelloWorldApplication({
rest: givenHttpServerConfig(),
disableConsoleLog: true,
});
}
});
async function givenAClient() {
app = new RestApplication({rest: givenHttpServerConfig()});
app.controller(
givenBodyParamController('/show-body-json', 'json'),
'Controller1',
);
app.controller(givenBodyParamController('/show-body'), 'Controller2');
await app.start();
client = createRestAppClient(app);
}
async function getApp() {
await sandbox.copyFile(resolve(__dirname, '../fixtures/package.json'));
await sandbox.copyFile(resolve(__dirname, '../fixtures/application.js'));
await sandbox.copyFile(
resolve(__dirname, '../fixtures/multiple.artifact.js'),
'controllers/multiple.controller.js',
);
const MyApp = require(resolve(SANDBOX_PATH, 'application.js')).BooterApp;
app = new MyApp({
rest: givenHttpServerConfig(),
});
}
async function givenAServer(
options: {rest: RestServerConfig} = {rest: {port: 0}},
) {
options.rest = givenHttpServerConfig(options.rest);
const app = new Application(options);
app.component(RestComponent);
return app.getServer(RestServer);
}
repo = new ProductRepository(db);
const CrudRestController = defineCrudRestController<
Product,
typeof Product.prototype.id,
'id'
>(Product, {basePath: '/products'});
class ProductController extends CrudRestController {
constructor() {
super(repo);
}
}
app = new RestApplication({rest: givenHttpServerConfig()});
app.controller(ProductController);
await app.start();
client = createRestAppClient(app);
}
async function givenAClient() {
app = new RestApplication({rest: givenHttpServerConfig()});
app.bodyParser(MultipartFormDataBodyParser);
app.controller(FileUploadController);
await app.start();
client = createRestAppClient(app);
}
});