Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Express
- let express = require("express");
- let app = express();
- app.enable('trust proxy');
- const path = require("path");
- const crypto = require('crypto');
- const Datastore = require('@google-cloud/datastore');
- // Static Folder
- app.use(express.static(__dirname + '/public/dist'));
- // Body Parser
- let bodyParser = require("body-parser");
- app.use(bodyParser.urlencoded({extended:true}));
- app.use(bodyParser.json());
- // Morgan
- let morgan = require("morgan");
- app.use(morgan('dev'));
- const datastore = Datastore();
- const query = datastore.createQuery('visit')
- .order('timestamp', { descending: true })
- .limit(10);
- // Routes
- // Get Users
- app.get("/customer", (req, res, next) => {
- console.log("Server > GET '/customer' ");
- return datastore.runQuery(query)
- .then((results) => {
- const entities = results[0];
- return results;//.map((entity) => `CNAME: ${entity.cname}, Phone: ${entity.phone}`);
- console.log(entity);
- })
- })
- app.all("*", (req,res,next) => {
- res.sendfile(path.resolve("./public/dist/index.html"));
- })
- // Server Listening @ 1337
- app.listen(8080, ()=> console.log("Server running at 8080"));
- import { Injectable } from '@angular/core';
- import { Customer } from '../customer';
- //import 'rxjs/rx';
- import { Observable } from 'rxjs/Observable';
- import { Http } from '@angular/http';
- @Injectable()
- export class CustomerService {
- constructor(private _http: Http) { }
- create(user: Customer) {
- return this._http.post('/customer', user).map(data => data.json()).toPromise();
- }
- destroy(user: Customer) {
- // return this._http.delete('/users/' + user._id).map(data => data.json()).toPromise();
- }
- update(user: Customer) {
- // return this._http.put('/users/' + user._id, user).map(data => data.json()).toPromise();
- }
- getUsers() {
- return this._http.get('/customer').map(data => data.json()).toPromise();
- }
- getUser(user: Customer) {
- // return this._http.post('/users' + user._id, user).toPromise();
- }
- }
- import { Component,OnInit } from '@angular/core';
- import { Customer } from '../customer';
- import { CustomerService } from './customer.service'
- import { Http } from '@angular/http';
- @Component({
- selector: 'ngx-form-layouts',
- styleUrls: ['./customer.component.scss'],
- templateUrl: './customer.component.html',
- })
- export class CustomerComponent implements OnInit {
- customer: Array<Customer>=[];
- constructor(private _customerService: CustomerService,private _http: Http ) { }
- ngOnInit() {
- this.getUsers();
- }
- getUsers() {
- this._customerService.getUsers().then(customer => this.customer = customer)
- .catch(err => console.log(err));
- // return this._http.get('/customer').map(data => data.json()).toPromise();
- }
- }
- <div class="row">
- <div class="col-lg-12">
- <nb-card>
- <nb-card-body>
- {{customer | json}}
- </nb-card-body>
- </nb-card>
- </div>
- </div>
Add Comment
Please, Sign In to add comment