-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |