-
-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #802 from lexoyo/silex_as_a_dependency
WIP: add custom unifile services
- Loading branch information
Showing
11 changed files
with
197 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
////////////////////////////////////////////////// | ||
// Silex, live web creation | ||
// http://projects.silexlabs.org/?/silex/ | ||
// | ||
// Copyright (c) 2012 Silex Labs | ||
// http://www.silexlabs.org/ | ||
// | ||
// Silex is available under the GPL license | ||
// http://www.silexlabs.org/silex/silex-licensing/ | ||
////////////////////////////////////////////////// | ||
|
||
// server options | ||
const serverOptions = {}; | ||
serverOptions.port = process.env.PORT || 6805; // 6805 is the date of sexual revolution started in paris france 8-) | ||
serverOptions.rootUrl = process.env.SERVER_URL || `http://localhost:${serverOptions.port}`; | ||
serverOptions.sessionSecret = process.env.SILEX_SESSION_SECRET || 'test session secret'; | ||
serverOptions.cePath = '/ce'; | ||
|
||
// electron app | ||
const electronOptions = { | ||
enabled: process.env.SILEX_ELECTRON || false, | ||
} | ||
|
||
// SSL options | ||
const sslOptions = { | ||
forceHttps: process.env.SILEX_FORCE_HTTPS, | ||
trustXFPHeader: process.env.SILEX_FORCE_HTTPS_TRUST_XFP_HEADER, | ||
privateKey: process.env.SILEX_SSL_PRIVATE_KEY, | ||
certificate: process.env.SILEX_SSL_CERTIFICATE, | ||
sslPort: process.env.SSL_PORT || 443, | ||
}; | ||
|
||
// cloud explorer options | ||
const ceOptions = { | ||
enableFtp: process.env.ENABLE_FTP, | ||
enableSftp: process.env.ENABLE_SFTP, | ||
enableWebdav: process.env.ENABLE_WEBDAV, | ||
githubClientId: process.env.GITHUB_CLIENT_ID, | ||
githubClientSecret: process.env.GITHUB_CLIENT_SECRET, | ||
dropboxClientId: process.env.DROPBOX_CLIENT_ID, | ||
dropboxClientSecret: process.env.DROPBOX_CLIENT_SECRET, | ||
enableFs: process.env.SILEX_DEBUG || process.env.SILEX_ELECTRON || process.env.ENABLE_FS, | ||
fsRoot: process.env.FS_ROOT, | ||
rootUrl: serverOptions.rootUrl, | ||
}; | ||
|
||
const publisherOptions = { | ||
rootUrl: serverOptions.rootUrl, | ||
port: serverOptions.port, | ||
} | ||
|
||
const exported = function() {}; | ||
exported.prototype = { | ||
ceOptions: ceOptions, | ||
serverOptions: serverOptions, | ||
publisherOptions: publisherOptions, | ||
electronOptions: electronOptions, | ||
sslOptions: sslOptions, | ||
}; | ||
module.exports = exported; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
////////////////////////////////////////////////// | ||
// Silex, live web creation | ||
// http://projects.silexlabs.org/?/silex/ | ||
// | ||
// Copyright (c) 2012 Silex Labs | ||
// http://www.silexlabs.org/ | ||
// | ||
// Silex is available under the GPL license | ||
// http://www.silexlabs.org/silex/silex-licensing/ | ||
////////////////////////////////////////////////// | ||
|
||
// node modules | ||
const Path = require('path'); | ||
const fs = require('fs'); | ||
const express = require('express'); | ||
const compression = require('compression'); | ||
const cookieParser = require('cookie-parser'); | ||
const session = require('cookie-session'); | ||
const serveStatic = require('serve-static'); | ||
const CloudExplorerRouter = require('./CloudExplorerRouter'); | ||
const WebsiteRouter = require('./WebsiteRouter.js'); | ||
const PublishRouter = require('./PublishRouter.js'); | ||
const SslRouter = require('./SslRouter.js'); | ||
const bodyParser = require('body-parser'); | ||
|
||
module.exports = function({ | ||
serverOptions, | ||
publisherOptions, | ||
ceOptions, | ||
electronOptions, | ||
sslOptions, | ||
}) { | ||
this.app = express(); | ||
|
||
// compress gzip when possible | ||
this.app.use(compression()); | ||
|
||
// cookie & session | ||
this.app.use(bodyParser.json({limit: '1mb'})); | ||
this.app.use(bodyParser.text({limit: '10mb'})); | ||
this.app.use(cookieParser()); | ||
this.app.use(session({ | ||
name: 'silex-session', | ||
secret: serverOptions.sessionSecret, | ||
})); | ||
|
||
// create the routes for unifile/CloudExplorer | ||
// and for Silex tasks | ||
this.ceRouter = new CloudExplorerRouter(ceOptions); | ||
this.websiteRouter = new WebsiteRouter(serverOptions, this.ceRouter.unifile); | ||
this.publishRouter = new PublishRouter(publisherOptions, this.ceRouter.unifile); | ||
this.sslRouter = new SslRouter(sslOptions, this.app); | ||
this.unifile = this.ceRouter.unifile; // for access by third party | ||
|
||
this.app.use(serverOptions.cePath, this.ceRouter); | ||
this.app.use(this.websiteRouter); | ||
this.app.use(this.publishRouter); | ||
this.app.use(this.sslRouter); | ||
|
||
// add static folders to serve silex files | ||
this.app.use('/', serveStatic(Path.join(__dirname, '../../dist/client'))); | ||
// debug silex, for js source map | ||
this.app.use('/js/src', serveStatic(Path.join(__dirname, '../../src'))); | ||
// the scripts which have to be available in all versions (v2.1, v2.2, v2.3, ...) | ||
this.app.use('/static', serveStatic(Path.join(__dirname, '../../static'))); | ||
|
||
// Start Silex as an Electron app | ||
if(electronOptions.enabled) { | ||
require(Path.join(__dirname, 'silex_electron')); | ||
} | ||
|
||
// server 'loop' | ||
this.app.listen(serverOptions.port, function() { | ||
console.log('Listening on ' + serverOptions.port); | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.