Skip to content

kunyan/server-side-include

Repository files navigation

Server Side Include

Build Status NPM (scoped) NPM (scoped) NPM (scoped)

Concept

Implement Server Side Includes with Node.js

Integration

Express

import { serverSideInclude } from '@server-side-include/express-middleware';
import express from 'express';

app.use(serverSideInclude());

app.use(express.static('public'));

app.listen(3000);

Vite

import { SSIPlugin } from '@server-side-include/vite-plugin';
import path from 'path';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    SSIPlugin({
      host: 'https://access.redhat.com',
      rejectUnauthorized: true,
      templatePath: path.resolve(__dirname, 'index.html'),
    }),
  ],
});
<!DOCTYPE html>
<html class="no-js nimbus pf-m-redhat-font">
  <head>
    <!--#include virtual="/_include_/init.html" -->
    <!--#include virtual="/services/chrome/head/$locale?legacy=false" -->
  </head>
  <body>
    <!--#include virtual="/services/chrome/header/$locale?legacy=false" -->
    <div class="container">
      <div id="chrometwo">
        <div id="root">Hello world</div>
        <!--#echo var="DATE_LOCAL" -->
      </div>
    </div>
    <!--#include virtual="/services/chrome/footer/$locale?legacy=false" -->
  </body>
</html>