Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/express-composition/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/example-express-composition
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

export * from './dist';
12 changes: 2 additions & 10 deletions examples/express-composition/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
"tslint": "lb-tslint",
"tslint:fix": "npm run tslint -- --fix",
"pretest": "npm run clean && npm run build",
"test": "lb-mocha --allow-console-logs \"dist/src/__tests__\"",
"test": "lb-mocha \"dist/__tests__/**/*.js\"",
"posttest": "npm run lint",
"test:dev": "lb-mocha --allow-console-logs dist/src/__tests__/**/*.js && npm run posttest",
"test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
"migrate": "node ./dist/src/migrate",
"prestart": "npm run build",
"start": "node ."
Expand All @@ -42,14 +42,6 @@
},
"author": "IBM Corp.",
"license": "MIT",
"files": [
"README.md",
"index.js",
"index.d.ts",
"dist/src",
"dist/index*",
"src"
],
"dependencies": {
"@loopback/boot": "^1.0.14",
"@loopback/context": "^1.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('NoteApplication', () => {

before('setupApplication', async () => {
({server, client, lbApp} = await setupExpressApplication());
await changeDataSourceConfig();
await givenNoteRepository();
});

Expand Down Expand Up @@ -57,4 +58,15 @@ describe('NoteApplication', () => {
async function givenNoteRepository() {
noteRepo = await lbApp.getRepository(NoteRepository);
}

async function changeDataSourceConfig() {
/**
* Override default config for DataSource for testing so we don't write
* test data to file when using the memory connector.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered using the approach we are recommending in https://loopback.io/doc/en/lb4/Testing-your-application.html#create-a-test-datasource? Maybe it's not a good one, IDK.

It would be great to have a single prescribed way, used consistently both in our docs and the example repos. I think that's out of scope of this pull request though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following how it was done in the Todo example, but I can definitely look into that way and update the examples/the docs in a different PR.

*/
lbApp.bind('datasources.config.ds').to({
name: 'ds',
connector: 'memory',
});
}
});
2 changes: 1 addition & 1 deletion examples/express-composition/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class NoteApplication extends BootMixin(
this.sequence(MySequence);

// Set up default home page
this.static('/', path.join(__dirname, '../../public'));
this.static('/', path.join(__dirname, '../public'));

// Customize @loopback/rest-explorer configuration here
this.bind(RestExplorerBindings.CONFIG).to({
Expand Down
4 changes: 2 additions & 2 deletions examples/express-composition/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export class ExpressServer {

// Custom Express routes
this.app.get('/', function(_req: Request, res: Response) {
res.sendFile(path.resolve('public/express.html'));
res.sendFile(path.join(__dirname, '../public/express.html'));
});
this.app.get('/hello', function(_req: Request, res: Response) {
res.send('Hello world!');
});

// Serve static files in the public folder
this.app.use(express.static('public'));
this.app.use(express.static(path.join(__dirname, '../public')));
}

public async boot() {
Expand Down
16 changes: 3 additions & 13 deletions examples/express-composition/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@loopback/build/config/tsconfig.common.json",
"include": [
"src",
"test",
"index.ts"
],
"exclude": [
"node_modules/**",
"packages/*/node_modules/**",
"**/*.d.ts"
],
"compilerOptions": {
"experimentalDecorators": true
}

"rootDir": "src"
},
"include": ["src"]
}