angularwebserver v1.1.3
Web Server Angular
Goals
Creation of a system allowing you to manage a web server hosting projects using Angular with Express.
Work too with the Ionic Project using Angular.
Table of contents
Installation
Prerequisites
Works with version of Node.Js superior or equal to 16.
Npm
You can install the library using npm:
npm install angularwebserver
Usage
There are two parts in this project, the first one is usefull for the route '/' and the other one for the route '/*' of you project.
Import
You can import the package using :
// if you are using CommonJs
const angularServer = require('angularwebserver');
// if you are using ES6
import {angularServer} from "angularwebserver";
Variables
Here are some variable which could be usefull for using this package and that you will see in the next part of this documentation.
link
The variable link is the link of the project you want to serve.
If you are on localhost, it will be "http://localhost:port".
dirname
The variable dirname is the name of the directory where you want to serve your project.
You can obtain it using the path package :
// if you are using CommonJs
const path = require('path');
// if you are using ES6
import * as path from "path";
const dirname = path.resolve('./');
This will find the path to where you launch your node project.
If you are using subpath, you don't have to specify the directory name, it will use the name of the subpath.
First part
app.get('/', function (req, res) {
angularServer.siteSlash(req, res, Link, dirname + '/directoryName');
});
Second part
app.get('/*', function (req, res) {
angularServer.siteRest(req, res, Link, dirname + '/directoryName');
});
Subpath
You can also use this package with subpath.
app.get('/subpath', function (req, res) {
angularServer.siteSlash(req, res, Link, dirname);
});
app.get('/subpath/*', function (req, res) {
angularServer.siteRest(req, res, Link, dirname);
});