-
Notifications
You must be signed in to change notification settings - Fork 5
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 #129 from donejs/revert-128-h2two
Revert "Use http2 module for https/http2 support"
- Loading branch information
Showing
31 changed files
with
468 additions
and
1,063 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
}, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"esversion": 6, | ||
"freeze": true, | ||
"indent": 2, | ||
"latedef": false, | ||
|
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ language: node_js | |
script: npm test | ||
node_js: | ||
- "8" | ||
- "10" | ||
- "9" |
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,10 +1,99 @@ | ||
var path = require('path'); | ||
|
||
module.exports = function(port, options) { | ||
let createApp = require("./app"); | ||
let createServers = require("./servers").create; | ||
var compression = require('compression'); | ||
var errorFormat = require('donejs-error-format'); | ||
var express = require('express'); | ||
var serveIndex = require('serve-index'); | ||
var debug = require('debug')('done-serve'); | ||
var middleware = require('done-ssr-middleware'); | ||
var fs = require('fs'); | ||
|
||
let app = createApp(options); | ||
let [mainServer] = createServers(port, options, app); | ||
var proxy = require('./proxy'); | ||
|
||
return mainServer; | ||
function notFoundHandler(req, res, next) { | ||
res.status(404); | ||
next(new Error('File not found')); | ||
} | ||
|
||
module.exports = function (options) { | ||
var app = express() | ||
.use(compression()); | ||
|
||
debug('Initializing done-serve application', options); | ||
|
||
if (options.configure) { | ||
options.configure(app); | ||
} | ||
|
||
if (options.proxy) { | ||
proxy(app, options); | ||
} | ||
|
||
app.use(express.static(path.join(options.path))); | ||
|
||
if(!options.static) { | ||
var steal = { | ||
config: path.join(options.path, 'package.json') + '!npm', | ||
liveReload: options.liveReload | ||
}; | ||
|
||
if(options.main) { | ||
steal.main = options.main; | ||
} | ||
|
||
var mw = middleware(steal, options); | ||
|
||
debug('Registering done-ssr-middleware'); | ||
app.use(mw); | ||
|
||
// Error handler | ||
app.use(function(error, request, response, next) { | ||
var parts = errorFormat.extract(error); | ||
var errorOptions = { | ||
liveReload: !!options.liveReload | ||
}; | ||
var html = errorFormat.html(parts, errorOptions); | ||
|
||
if(options.logErrors !== false) { | ||
console.log('\033c'); | ||
console.error(error.stack); | ||
} | ||
|
||
response.status(500).type('html').end(html); | ||
}); | ||
} else { | ||
// Unobtrusively handle pushstate routing when SSR is turned off. | ||
app.get('*', function (req, res, next) { | ||
var urlParts = path.parse(req.url); | ||
var isPushstateRoute = !urlParts.ext || urlParts.name.includes('?'); | ||
if (isPushstateRoute) { | ||
var env = process.env.NODE_ENV || 'development'; | ||
var htmlPath = path.join(options.path, './' + env + '.html'); | ||
if (!fs.existsSync(htmlPath)) { | ||
htmlPath = path.join(options.path, './production.html'); | ||
} | ||
if (fs.existsSync(htmlPath)) { | ||
return res.sendFile(htmlPath); | ||
} | ||
} | ||
return next(); | ||
}); | ||
|
||
app.use(serveIndex(path.join(options.path), { icons: true })); | ||
app.use(notFoundHandler); | ||
|
||
if(options.errorPage) { | ||
var filename = path.join(process.cwd(), options.errorPage); | ||
|
||
debug('Registering pushState file', filename); | ||
|
||
app.use(function(err, req, res, next) { | ||
debug('Pushstate error handler', filename); | ||
res.status(200); | ||
res.sendFile(filename); | ||
}); | ||
} | ||
} | ||
|
||
return app; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.