GithubHelp home page GithubHelp logo

srogers909 / angular-http-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simonh1000/angular-http-server

0.0 1.0 0.0 179 KB

Simple http-server for single-page apps (SPAs)

Home Page: https://www.npmjs.com/package/angular-http-server

License: Apache License 2.0

HTML 8.16% JavaScript 91.84%

angular-http-server's Introduction

Single Page App dev-server

A simple dev-server designed for Single Page App (SPA) developers. angular-http-server is not, and makes no claims to be, a production server.

It returns a file if it exists (ex. your-icon.png, index.html), routes all other requests to index.html (rather than giving a 404 error) so that you SPA's routing can take over. The only time it will error out is if it can't locate the index.html file.

Originally designed for my Angular work, this dev-server will work with any Single Page App (SPA) framework that uses URL routing (React, Vue, Elm, ...).

To use:

npm install -g angular-http-server
cd /path/to/site
angular-http-server

And browse to localhost:8080.

Options

Specify a port using -p <port number>

angular-http-server -p 9000

Open in a default browser automatically by using --open alias -o

angular-http-server --open

HTTPS can be enabled (using a generated self-signed certificate) with --https or --ssl

angular-http-server --https

You may manually specify the paths to your self-signed certificate using the --key and --cert flags

angular-http-server --https --key ./secret/key.pem --cert ./secret/cert.pem

CORS can be enabled with the --cors flag

angular-http-server --cors

Specify a path to serve from

angular-http-server --path example

Specify the base href of the application

angular-http-server --baseHref myapp

Disable logging

angular-http-server --silent

All options can be specified by a config file, optionally read via --config flag. CLI options take precedence over any options read from the config file.

angular-http-server --config configs/angular-http-server.config.js

Feedback via: https://github.com/simonh1000/angular-http-server

Config File

The config file can either export an object of parameters, or a function that will be passed in the parsed argv from minimalist.

Simple example:

module.exports = {
    p: 8081,
    cors: true,
    silent: true,
};

Complicated example:

module.exports = (argv) => {
    const config = {
        cors: true,
    };

    if (argv.p === 443) {
        config.ssl = true;
    }

    return config;
};

Self-Signed HTTPS Use

Production

The --https or --ssl flags are intended for development and/or testing purposes only. Self-signed certificates do not properly verify the identity of the web app and they will cause an end-users web browser to display an error. Only use angular-http-server with a self-signed certificate for development and/or testing. This can be accomplished by using the self-signed certificate generated when you pass the --https/--ssl flag. An example of when you should use this feature is with end-to-end testing suites such as Protractor. or other suites which require the SPA application to be actively served.

Changelog

  • 1.9.0 - adds --baseHref (thanks bertbaron)
  • 1.8.0 - rewrite of path resolution (thanks dpraul)
  • 1.7.0 - add option to include own ssl certificate (thanks dpraul)
  • 1.6.0 - add --config option (thanks dpraul)
  • 1.5.0 - add --open option (thanks tluanga34)
  • 1.4.0 - add --path option (thanks nick-bogdanov)

Contributing

Contributions are welcome, but do create an issue first to discuss.

Use prettier for formatting

Testing

Run unit tests with

$ yarn run test

Testing - try:

node angular-http-server.js --path example --ssl -p 9000

angular-http-server's People

Contributors

ckaeslin avatar dalem-seagate avatar dependabot[bot] avatar dpraul avatar greenygh0st avatar nick-bogdanov avatar simonh1000 avatar tluanga34 avatar

Watchers

 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.