Giter Club home page Giter Club logo

ssi-web-server's Introduction

Server Side Includes Web Server

Contents

Requirements

Node version 16 npm

No third party libraries were used.

Usage

Run the following commands npm ci npm start

Then go to localhost:8000 - this will by default serve you the index.shtml file in the app folder. However routing is included and so going to localhost:8000/example.shtml will serve the example shtml file instead.

Custom Host and Port

By default, the hostname is set to 'localhost' and the port is set to 8000. If you would like to override either/or both of these, you can do so by setting Environment Variables. For example:

NODE_HOST=custom_hostname NODE_PORT=1234 npm start

How it works

server.js

This is a basic http server. When it receives a request, if the request requires a favicon, return the Adobe favicon.

Otherwise, get the HTML page from the local file system. There is a very basic in memory cache that means if an page is required twice, we will pull it from the cache and serve it from there.

If the file is not in the cache, we create a new instance of SSIHtmlParser (see htmlparser.js) and parse the file.

 

htmlParser.js

The class parses the file at the given filepath and if it contains an SSI include element, we create a new instance of the parser and recursively call it with the linked file until we can assemble a full html page.

This allows .shtml files to include other .shtml files in a nested fashion.

 

helpers/asyncStringReplace.js

This function was copied from here and allows us to do string replacements with asynchronous functions.

 

app folder

This folder contains html and shtml files. The partials folder contains smaller elements such as the header, sub header and footer elements. These are very simple and are mainly there to demonstrate how the parser works.

Future improvements

This repo could be improved with more time in a number of ways - here are a couple of quick suggestions:

  • Tests!
  • Moving to Typescript
  • Ability to handle more file types
  • Ability to handle more directives
  • Ability for the Include directive to suport error and virtual attributes
  • Better error handling
  • Configure eslint and prettier within the project
  • Automatically restart the server on change in development mode

Resources used:

ssi-web-server's People

Watchers

Jack Wilkinson 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.