Skip to content

Full stack starter kit featuring Angular 7, Spring boot and stateless JWT authentication.

License

Notifications You must be signed in to change notification settings

bfwg/angular-spring-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StackShare Build Status Maintenance Status License MIT

Spring Boot and Angular 2

Angular2 Spring Boot JWT Starter

An Angular full stack starter kit featuring Angular 4, Router, Forms, Http, Services, Spring boot, JSON Web Token

If you're looking for using Angular 1.x for frontend implementation, please check out springboot-jwt-starter A Spring Boot token-based security starter kit featuring AngularJS and Spring Boot (JSON Web Token)

Springboot JWT Starter

Quick start

Make sure you have Maven and Java 1.7 or greater Make sure you also have NPM 3.1, Node 6.9.5 and [email protected] globally installed

# clone our repo
# --depth 1 removes all but one .git commit history
git clone --depth 1 https://github.com/bfwg/angular-spring-starter.git

# change directory to the repo's frontend folder
cd angular-spring-starter/frontend

# install the frontend dependencies with npm
# npm install @angular/[email protected] -g
npm install

# build frontend project to /server/src/main/resources/static folder
ng build

# change directory to the repo's backend folder
cd ../server

# install the server dependencies with mvn
mvn install

# start the server
mvn spring-boot:run

# the app will be running on port 8080

There are two user accounts present to demonstrate the different levels of access to the endpoints in the API and the different authorization exceptions:

Admin - admin:123
User - user:123

For more detailed configuration/documentation, please check out the frontend and server folder.

Development

Since the frontend app needs a dev-server for a faster development speed, we need a way to proxy the request to our spring boot backend which is running on port 8080. I'm using nginx.

Nginx configuration for Development

Put the below code snippet in your nginx.conf file. We are proxying everything to port 4201.

server {
    listen       4201;

    location / {
        proxy_pass http://localhost:4200;
        proxy_set_header  Host             $http_host;
        proxy_set_header  X-Real-IP        $remote_addr;
        proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
    }

    location ~ ^/(api|auth) {
        proxy_pass http://localhost:8080;
        proxy_set_header  Host             $http_host;
        proxy_set_header  X-Real-IP        $remote_addr;
        proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

Nginx configuration for Production

Please build the frontend app first by running ng build in the frontend folder. Put the below code snippet in your nginx.conf file. We are proxying everything to port 80, and redirecting everything to index.html.

server {
    listen      80;
    index index.html index.htm;
    server_name localhost;
    root /path/to/angular-spring-starter/server/src/main/resources/static;

    location / {
        try_files $uri $uri/ /index.html;
        proxy_pass http://localhost:8080;
        proxy_set_header  Host             $http_host;
        proxy_set_header  X-Real-IP        $remote_addr;
        proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
    
    location ~ ^/(api|auth) {
        proxy_pass http://localhost:8080;
        proxy_set_header  Host             $http_host;
        proxy_set_header  X-Real-IP        $remote_addr;
        proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

JSON Web Token

JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties. for more info, checkout https://jwt.io/

Token authentication is a more modern approach and is designed solve problems session IDs stored server-side can’t. Using tokens in place of session IDs can lower your server load, streamline permission management, and provide better tools for supporting a distributed or cloud-based infrastructure.

-- Stormpath

Contributing

I'll accept pretty much everything so feel free to open a Pull-Request

This project is inspired by


License

MIT