Giter Site home page Giter Site logo

nchait / ourcosmos Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 1.73 MB

Uses the NASA API and groups pictures into collections and attributes those collections to their creators

TypeScript 70.97% JavaScript 19.31% HTML 9.10% CSS 0.63%
typescript angular2 api-client restful-api

ourcosmos's Introduction

Angular to Node HTTP GET

A sample project to demostrate HTTP request from Angular to web service running on Node server


Node Server

Start the Node server using the following commands:

cd server
node server.js

To test the server, send a GET request to https://node-angular-lgobinath.c9users.io:8081/api

Note that the server is running on port 8081 because both Angular client and Node cannot run on same port. In this project we run Node on 8081 and Angular app on 8080

Angular Client

Start the Angular project using the following commands in another terminal

cd client
npm start

If you do not prefer npm start, use the following command instead:

ng serve --proxy-config proxy.conf.json --host 0.0.0.0 --port 8080 --disableHostCheck

Proxy Configuration

The proxy configuration used in Cloud 9:

{
    "/api/*": {
        "target": "https://node-angular-lgobinath.c9users.io:8081",
        "secure": false,
        "changeOrigin": true,
        "logLevel": "info"
    }
}

In the above configuration, "logLevel": "info" is used to print information about the proxy which is an optional property. The "changeOrigin": true is required only in Cloud 9 environment. Those who are developing this project in their own computer, need a proxy configuration as given below:

{
    "/api/*": {
        "target": "http://localhost:8081",
        "secure": false
    }
}

To make the life easier, npm start command is modified in the package.json as given below:

{
  "name": "client",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.json --host 0.0.0.0 --port 8080 --disableHostCheck",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  ...
}

Reference

See the commits for step by step code changes.

ourcosmos's People

Stargazers

Noah Chait avatar

Watchers

James Cloos avatar Gobinath Loganathan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.