Skip to content

Commit

Permalink
Added test fixed js serving error
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-dspeed committed Sep 29, 2016
1 parent b24ffa0 commit 06143b9
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 3 deletions.
31 changes: 31 additions & 0 deletions dssrv.sublime-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"folders":
[
{
"file_exclude_patterns": [
"*.sublime-*"
],
"folder_exclude_patterns": [
".*",
"kirby",
"panel",
"node_modules",
"bower_components"
],
"path": "."
},
{
"file_exclude_patterns": [
"*.sublime-*"
],
"folder_exclude_patterns": [
".*",
"kirby",
"panel",
"node_modules",
"bower_components"
],
"path": "/Users/lunelson/Git/packages/terraform"
}
]
}
68 changes: 67 additions & 1 deletion lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,54 @@ var fallback = exports.fallback = function(req, rsp, next){
skin(req, rsp, [custom200static, custom200dynamic, notFound], next)
}

exports.db = function(req, rsp, next){
skin(req, rsp, [
poly,
function(req, rsp, next){
req.setup.config.globals.title="DAMN!"
/*
const sourceFile= {
"projectPath" : "/path/to/app",
"publicPath" : "/path/to/app/public",
"config" : { "globals": req.setup.config.globals }
}
*/



var sourceFile = 'index.ejs'
// Will look automaticly for layout of that ejs file :)

var planet = prerender.root(req.projectPath+'/videos', { "title": "Bitchin" })

planet.render(sourceFile, { "title": "Override the global title" }, function(error, body){
console.log(error,body)
if(error){
// TODO: make this better
rsp.statusCode = 404;
rsp.end("There is an error in your " + sourceFile + " file")
}else{
if(!body) return next()
console.log(JSON.stringify(body))
// Option for setting headers in data json
if (req.setup.config.headers) console.log(req.setup.config.headers)

var type = helpers.mimeType("html")
var charset = mime.charsets.lookup(type)
rsp.setHeader('Content-Type', type + (charset ? '; charset=' + charset : ''));
rsp.setHeader('Content-Length', Buffer.byteLength(body, charset));
rsp.statusCode = 200;
rsp.end(body)
}

})


}
], next)
}


var notFound = exports.notFound = function(req, rsp, next){
skin(req, rsp, [custom404static, custom404dynamic, default404], next)
}
Expand Down Expand Up @@ -200,6 +248,7 @@ var custom200dynamic = function(req, rsp, next){
if(!body) return next()
var type = helpers.mimeType("html")
var charset = mime.charsets.lookup(type)
if (req.setup.config.headers) console.log(req.setup.config.headers)
rsp.setHeader('Content-Type', type + (charset ? '; charset=' + charset : ''));
rsp.setHeader('Content-Length', Buffer.byteLength(body, charset));
rsp.statusCode = 200;
Expand Down Expand Up @@ -335,6 +384,21 @@ exports.mwl = function(req, rsp, next){
}
}


/*
SetHeaders
*/
exports.setConfigHeaders = function() {
if (req.setup.config.headers) console.log(req.setup.config.headers)
// rsp.setHeader('Content-Type', mimeType + (charset ? '; charset=' + charset : ''))
// rsp.setHeader('Content-Length', Buffer.byteLength(body, charset));
// rsp.
}



/**
* Static
*
Expand All @@ -346,7 +410,8 @@ exports.static = function(req, res, next) {
var redirect = true

if ('GET' != req.method && 'HEAD' != req.method) return next()
if (['js'].indexOf(path.extname(req.url).replace(/^\./, '')) !== -1) return next()
// Fixes JS Delivery
// if (['js'].indexOf(path.extname(req.url).replace(/^\./, '')) !== -1) return next()

var pathn = parse(req).pathname;
var pause = utilsPause(req);
Expand Down Expand Up @@ -525,6 +590,7 @@ exports.process = function(req, rsp, next){
var charset = mime.charsets.lookup(mimeType)
var body = helpers.cssError(locals)
rsp.statusCode = 200
// SetHeaders
rsp.setHeader('Content-Type', mimeType + (charset ? '; charset=' + charset : ''))
rsp.setHeader('Content-Length', Buffer.byteLength(body, charset));
rsp.end(body)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dssrv",
"version": "1.0.3",
"version": "1.0.4",
"description": "DIREKTSPEED Server https://dspeed.eu",
"author": "Frank Lemanschik <[email protected]",
"contributors":
Expand Down
2 changes: 2 additions & 0 deletions test/apps/headers/invalid-pug.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1 Hello Jade
if foo()
3 changes: 2 additions & 1 deletion test/apps/headers/valid-js.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
alert("hello world")
// alert("hello world")
console.log('fine')
1 change: 1 addition & 0 deletions test/apps/headers/valid-pug.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h1 Hello World

0 comments on commit 06143b9

Please sign in to comment.