aboutsummaryrefslogtreecommitdiffstats
path: root/cds-ui/server/src
diff options
context:
space:
mode:
authorArundathi Patil <arundpil@in.ibm.com>2019-01-17 14:10:08 +0530
committerArundathi Patil <arundpil@in.ibm.com>2019-01-17 08:44:04 +0000
commit85db5b03a1fb5c2544559774b2f37f2ab108e1e4 (patch)
tree75a85e6178aeb4e24092f9102cefcccb61bb736b /cds-ui/server/src
parent22ca2adc867594e1c1fe9ff0b5750869e2eda282 (diff)
Seed code for loopback server
Added seed project structure for loopback server. This will act as intermediate layer between UI and backend. The angular UI app will be serverd through this server. Issue-ID: CCSDK-943 Change-Id: I03259782927eda0d7e5bff989f61a36f09a3afd8 Signed-off-by: Arundathi Patil <arundpil@in.ibm.com>
Diffstat (limited to 'cds-ui/server/src')
-rw-r--r--cds-ui/server/src/application.ts63
-rw-r--r--cds-ui/server/src/controllers/README.md30
-rw-r--r--cds-ui/server/src/controllers/index.ts22
-rw-r--r--cds-ui/server/src/controllers/ping.controller.ts72
-rw-r--r--cds-ui/server/src/datasources/README.md24
-rw-r--r--cds-ui/server/src/index.ts37
-rw-r--r--cds-ui/server/src/migrate.ts41
-rw-r--r--cds-ui/server/src/models/README.md24
-rw-r--r--cds-ui/server/src/repositories/README.md24
-rw-r--r--cds-ui/server/src/sequence.ts56
10 files changed, 393 insertions, 0 deletions
diff --git a/cds-ui/server/src/application.ts b/cds-ui/server/src/application.ts
new file mode 100644
index 000000000..463f330b8
--- /dev/null
+++ b/cds-ui/server/src/application.ts
@@ -0,0 +1,63 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+============LICENSE_END============================================
+*/
+
+import { BootMixin } from '@loopback/boot';
+import { ApplicationConfig } from '@loopback/core';
+import {
+ RestExplorerBindings,
+ RestExplorerComponent,
+} from '@loopback/rest-explorer';
+import { RepositoryMixin } from '@loopback/repository';
+import { RestApplication } from '@loopback/rest';
+import { ServiceMixin } from '@loopback/service-proxy';
+import * as path from 'path';
+import { MySequence } from './sequence';
+
+export class CdsUiServerApplication extends BootMixin(
+ ServiceMixin(RepositoryMixin(RestApplication)),
+) {
+ constructor(options: ApplicationConfig = {}) {
+ super(options);
+
+ // Set up the custom sequence
+ this.sequence(MySequence);
+
+ // Set up default home page
+ this.static('/', path.join(__dirname, '../../public'));
+
+ // Customize @loopback/rest-explorer configuration here
+ this.bind(RestExplorerBindings.CONFIG).to({
+ path: '/explorer',
+ });
+ this.component(RestExplorerComponent);
+
+ this.projectRoot = __dirname;
+ // Customize @loopback/boot Booter Conventions here
+ this.bootOptions = {
+ controllers: {
+ // Customize ControllerBooter Conventions here
+ dirs: ['controllers'],
+ extensions: ['.controller.js'],
+ nested: true,
+ },
+ };
+ }
+}
diff --git a/cds-ui/server/src/controllers/README.md b/cds-ui/server/src/controllers/README.md
new file mode 100644
index 000000000..837a462dc
--- /dev/null
+++ b/cds-ui/server/src/controllers/README.md
@@ -0,0 +1,30 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+============LICENSE_END============================================
+*/
+
+# Controllers
+
+This directory contains source files for the controllers exported by this app.
+
+To add a new empty controller, type in `lb4 controller [<name>]` from the
+command-line of your application's root directory.
+
+For more information, please visit
+[Controller generator](http://loopback.io/doc/en/lb4/Controller-generator.html).
diff --git a/cds-ui/server/src/controllers/index.ts b/cds-ui/server/src/controllers/index.ts
new file mode 100644
index 000000000..bf2bd6fb7
--- /dev/null
+++ b/cds-ui/server/src/controllers/index.ts
@@ -0,0 +1,22 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+============LICENSE_END============================================
+*/
+
+export * from './ping.controller';
diff --git a/cds-ui/server/src/controllers/ping.controller.ts b/cds-ui/server/src/controllers/ping.controller.ts
new file mode 100644
index 000000000..d3098bc69
--- /dev/null
+++ b/cds-ui/server/src/controllers/ping.controller.ts
@@ -0,0 +1,72 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+============LICENSE_END============================================
+*/
+
+import { Request, RestBindings, get, ResponseObject } from '@loopback/rest';
+import { inject } from '@loopback/context';
+
+/**
+ * OpenAPI response for ping()
+ */
+const PING_RESPONSE: ResponseObject = {
+ description: 'Ping Response',
+ content: {
+ 'application/json': {
+ schema: {
+ type: 'object',
+ properties: {
+ greeting: { type: 'string' },
+ date: { type: 'string' },
+ url: { type: 'string' },
+ headers: {
+ type: 'object',
+ properties: {
+ 'Content-Type': { type: 'string' },
+ },
+ additionalProperties: true,
+ },
+ },
+ },
+ },
+ },
+};
+
+/**
+ * A simple controller to bounce back http requests
+ */
+export class PingController {
+ constructor(@inject(RestBindings.Http.REQUEST) private req: Request) { }
+
+ // Map to `GET /ping`
+ @get('/ping', {
+ responses: {
+ '200': PING_RESPONSE,
+ },
+ })
+ ping(): object {
+ // Reply with a greeting, the current time, the url, and request headers
+ return {
+ greeting: 'Hello from LoopBack',
+ date: new Date(),
+ url: this.req.url,
+ headers: Object.assign({}, this.req.headers),
+ };
+ }
+}
diff --git a/cds-ui/server/src/datasources/README.md b/cds-ui/server/src/datasources/README.md
new file mode 100644
index 000000000..2d4d4c3be
--- /dev/null
+++ b/cds-ui/server/src/datasources/README.md
@@ -0,0 +1,24 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+============LICENSE_END============================================
+*/
+
+# Datasources
+
+This directory contains config for datasources used by this app.
diff --git a/cds-ui/server/src/index.ts b/cds-ui/server/src/index.ts
new file mode 100644
index 000000000..04852494f
--- /dev/null
+++ b/cds-ui/server/src/index.ts
@@ -0,0 +1,37 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+============LICENSE_END============================================
+*/
+
+import { CdsUiServerApplication } from './application';
+import { ApplicationConfig } from '@loopback/core';
+
+export { CdsUiServerApplication };
+
+export async function main(options: ApplicationConfig = {}) {
+ const app = new CdsUiServerApplication(options);
+ await app.boot();
+ await app.start();
+
+ const url = app.restServer.url;
+ console.log(`Server is running at ${url}`);
+ console.log(`Try ${url}/ping`);
+
+ return app;
+}
diff --git a/cds-ui/server/src/migrate.ts b/cds-ui/server/src/migrate.ts
new file mode 100644
index 000000000..0897b980b
--- /dev/null
+++ b/cds-ui/server/src/migrate.ts
@@ -0,0 +1,41 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+============LICENSE_END============================================
+*/
+
+import { CdsUiServerApplication } from './application';
+
+export async function migrate(args: string[]) {
+ const existingSchema = args.includes('--rebuild') ? 'drop' : 'alter';
+ console.log('Migrating schemas (%s existing schema)', existingSchema);
+
+ const app = new CdsUiServerApplication();
+ await app.boot();
+ await app.migrateSchema({ existingSchema });
+
+ // Connectors usually keep a pool of opened connections,
+ // this keeps the process running even after all work is done.
+ // We need to exit explicitly.
+ process.exit(0);
+}
+
+migrate(process.argv).catch(err => {
+ console.error('Cannot migrate database schema', err);
+ process.exit(1);
+});
diff --git a/cds-ui/server/src/models/README.md b/cds-ui/server/src/models/README.md
new file mode 100644
index 000000000..b4bbe4ac0
--- /dev/null
+++ b/cds-ui/server/src/models/README.md
@@ -0,0 +1,24 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+============LICENSE_END============================================
+*/
+
+# Models
+
+This directory contains code for models provided by this app.
diff --git a/cds-ui/server/src/repositories/README.md b/cds-ui/server/src/repositories/README.md
new file mode 100644
index 000000000..dc7af9055
--- /dev/null
+++ b/cds-ui/server/src/repositories/README.md
@@ -0,0 +1,24 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+============LICENSE_END============================================
+*/
+
+# Repositories
+
+This directory contains code for repositories provided by this app.
diff --git a/cds-ui/server/src/sequence.ts b/cds-ui/server/src/sequence.ts
new file mode 100644
index 000000000..b27093147
--- /dev/null
+++ b/cds-ui/server/src/sequence.ts
@@ -0,0 +1,56 @@
+/*
+============LICENSE_START==========================================
+===================================================================
+Copyright (C) 2018-19 IBM Intellectual Property. All rights reserved.
+===================================================================
+
+Unless otherwise specified, all software contained herein is licensed
+under the Apache License, Version 2.0 (the License);
+you may not use this software except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+============LICENSE_END============================================
+*/
+
+import { inject } from '@loopback/context';
+import {
+ FindRoute,
+ InvokeMethod,
+ ParseParams,
+ Reject,
+ RequestContext,
+ RestBindings,
+ Send,
+ SequenceHandler,
+} from '@loopback/rest';
+
+const SequenceActions = RestBindings.SequenceActions;
+
+export class MySequence implements SequenceHandler {
+ constructor(
+ @inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
+ @inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams,
+ @inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
+ @inject(SequenceActions.SEND) public send: Send,
+ @inject(SequenceActions.REJECT) public reject: Reject,
+ ) { }
+
+ async handle(context: RequestContext) {
+ try {
+ const { request, response } = context;
+ const route = this.findRoute(request);
+ const args = await this.parseParams(request, route);
+ const result = await this.invoke(route, args);
+ this.send(response, result);
+ } catch (err) {
+ this.reject(context, err);
+ }
+ }
+}