Skip to content

Single site mode

Alex Hoyau edited this page Dec 27, 2020 · 5 revisions

If you read this because you got an error saying "You need to specify which website I am supposed to open", you will need to read the "about" section below and probably contact the administrator of the platform which lead you to Silex editor

About the Single Site Mode

The single site mode is a way to make Silex behave like an editor for one website only. It is the way to go if your application manages the websites and you your app to open Silex to edit just the website the user is considering to edit.

Silex will look for the parameters path and service in the URL and then open the corresponding website.

This also means that Silex will:

  • skip the Dashboard and open a website directly
  • prevent the user from opening another site (hide the open menu and disable the shortcut)
  • prevent the user from "saving as"

This is how the file menu looks like in the single site mode, without "save as" and "open"

Silex in Single Site Mode

This mode is meant to be used with a custom integration of Silex, so you will need to have a nodejs project with Silex as an npm dependency. Also this doc "Integrate Silex with your infrastructure" may be useful if you want to authenticate the user yourself and provide the hosting.

Activate the single site mode

Set up the project

First you need a nodejs project with Silex as an npm dependency.

Custom index.html to display Silex

Then you need to change the HTML which loads Silex, in order to pass options to Silex. There is a proper way to do this without altering the code of Silex, so that you can keep your changes when updating Silex for example.

1- create a pug file called index.pug which will "extend" Silex index.html page:

extends ./node_modules/silex-website-builder/src/html/index.jade
append silex-options
  script.
    silex.config.singleSiteMode = true;

2- add the pug build to your package.json in order to generate a new HTML page to serve Silex

{
    "build": "pug index.pug -o dist/",
}

3- in order to serve the new HTML page in place of Silex index.html, add this line to your index.js (the file which creates the Silex server)

// serve modified html
silex.app.use('/', serveStatic(path.resolve('./dist/')));

If you have any questions please get in touch with Silex issues

WARNING: Support for Silex v2 has stopped. Try Silex v3 alpha, Read about it, Subscribe to the newsletter

Clone this wiki locally