Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const webpack = require('webpack');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- module.exports = {
- entry: './src/main.ts',
- module: {
- rules: [
- {
- test: /.ts$/,
- use: ['ts-loader', 'angular2-template-loader'],
- exclude: /node_modules/
- },
- {
- test: /.(html|css)$/,
- loader: 'raw-loader'
- },
- ]
- },
- resolve: {
- extensions: ['.ts', '.js']
- },
- plugins: [
- new HtmlWebpackPlugin({
- template: './src/index.html',
- filename: 'index.html',
- inject: 'body'
- }),
- new webpack.DefinePlugin({
- // global app config object
- config: JSON.stringify({
- apiUrl: 'http://localhost:4000'
- })
- })
- ],
- optimization: {
- splitChunks: {
- chunks: 'all',
- },
- runtimeChunk: true
- },
- devServer: {
- historyApiFallback: true
- }
- };
- import { Injectable } from '@angular/core';
- import { HttpClient } from '@angular/common/http';
- import { map } from 'rxjs/operators';
- @Injectable()
- export class AuthenticationService {
- constructor(private http: HttpClient) { }
- login(username: string, password: string) {
- return this.http.post<any>(`${config.apiUrl}/users/authenticate`, { username: username, password: password })
- .pipe(map(user => {
- // login successful if there's a jwt token in the response
- if (user && user.token) {
- // store user details and jwt token in local storage to keep user logged in between page refreshes
- localStorage.setItem('currentUser', JSON.stringify(user));
- }
- return user;
- }));
- }
- logout() {
- // remove user from local storage to log user out
- localStorage.removeItem('currentUser');
- }
- }
- import { Injectable } from '@angular/core';
- import { HttpClient } from '@angular/common/http';
- import { User } from '../_models/user';
- @Injectable()
- export class UserService {
- constructor(private http: HttpClient) { }
- getAll() {
- return this.http.get<User[]>(`${config.apiUrl}/users`);
- }
- getById(id: number) {
- return this.http.get(`${config.apiUrl}/users/` + id);
- }
- register(user: User) {
- return this.http.post(`${config.apiUrl}/users/register`, user);
- }
- update(user: User) {
- return this.http.put(`${config.apiUrl}/users/` + user.id, user);
- }
- delete(id: number) {
- return this.http.delete(`${config.apiUrl}/users/` + id);
- }
- }
- {
- "extends": "../tsconfig.json",
- "compilerOptions": {
- "outDir": "../out-tsc/app",
- "module": "es2015",
- "types": [
- "webpack-env"
- ]
- },
- "exclude": [
- "src/test.ts",
- "**/*.spec.ts"
- ]
- }
- {
- "extends": "../tsconfig.json",
- "compilerOptions": {
- "outDir": "../out-tsc/spec",
- "module": "commonjs",
- "types": [
- "jasmine",
- "node",
- "webpack-env"
- ]
- },
- "files": [
- "test.ts",
- "polyfills.ts"
- ],
- "include": [
- "**/*.spec.ts",
- "**/*.d.ts"
- ]
- }
Add Comment
Please, Sign In to add comment