Skip to content

Commit

Permalink
Merge 0302da8 into c601c4c
Browse files Browse the repository at this point in the history
  • Loading branch information
nabdelgadir committed Jan 29, 2019
2 parents c601c4c + 0302da8 commit 308202d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/todo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@
"@loopback/http-caching-proxy": "^1.0.5",
"@loopback/testlab": "^1.0.5",
"@loopback/tslint-config": "^2.0.0",
"@types/express": "^4.16.1",
"@types/lodash": "^4.14.109",
"@types/node": "^10.11.2",
"lodash": "^4.17.10",
"p-event": "^2.2.0",
"path": "^0.12.7",
"tslint": "^5.12.0",
"typescript": "^3.2.2"
},
Expand Down
11 changes: 11 additions & 0 deletions examples/todo/src/express-app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as exp from 'express';
const express = require('express');

export class ExpressApplication {
app: exp.Application;
constructor() {
// all calls will be app.app.function() if app = new ExpressApplication()
this.app = new express();
this.app.use(express.static('./public'));
}
}
43 changes: 43 additions & 0 deletions examples/todo/src/express.index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: @loopback/example-todo
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {TodoListApplication} from './application';
import {ApplicationConfig} from '@loopback/core';
import {Request, Response} from '@loopback/rest';
const express = require('express');
const path = require('path');
// const pEvent = require('p-event');

export async function main(options: ApplicationConfig = {}) {
const app = new express();
const lbApp = new TodoListApplication(options);

// Mount LB4 as our REST API
await lbApp.boot();
lbApp.basePath('/api');

// Expose the front-end assets via Express, not as LB4 route
app.use(lbApp.requestHandler);
app.use(express.static('./public'));

// Add any custom Express routes
app.get('/', function(_req: Request, res: Response) {
res.sendFile(path.resolve('public/index.html'));
});
app.get('/get', function(_req: Request, res: Response) {
res.send('Get!');
});

app.listen(3000);

// This line doesn't work right now
// await pEvent(app, 'listening');

console.log('TodoList example listening on http://127.0.0.1:3000!');

return app;
}

export {TodoListApplication};

0 comments on commit 308202d

Please sign in to comment.