Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const deconstructUrl = input => {
const unescaped = decodeURI(input)
const deconstructed = url.parse(unescaped, true)
// Deal with the (silly) way arrays are handled
// https://github.com/Patreon/url-factory/blob/master/src/index.js#L4
map(deconstructed.query, (item, key) => {
// Handle the string-encoded empty array
if (item === '[]') {
deconstructed.query[key] = []
// Handle the fact that [ 'a', 'b' ] is encoded as "a,b"
} else if (includes(item, ',')) {
deconstructed.query[key] = item.split(',')
// Handle the fact that [ 'a' ] is encoded as "a"
} else if (key === 'include' && item.length) {
deconstructed.query[key] = [item]
}
})
export default async function (instance, request, response, requestedAt) {
const serverModifiers = instance._modifiers
// run server (before) modifiers
const serverBefore = serverModifiers.before
if (serverBefore) {
await serverBefore.execute()
}
// parse route
const router = instance._router
const url = request.url
const parsed = parseUrl(url, false)
const pathname = parsed.pathname.replace(/\/{2,}/g, '/')
const route = router.find(pathname, request.method)
let final
let context = createContext(instance, request, response, requestedAt, pathname, parsed.query)
if (route) {
const routeData = route.data
const routeModifiers = routeData.modifiers
// run route (before) modifiers
const routeBefore = routeModifiers.before
if (routeBefore) {
final = await routeBefore.execute(context(), true)
}
if (final === undefined) {
// method resolver
const resolver = routeData.resolver
const ctx = context(true)
import JuttleViewer from './components/juttle-viewer';
import 'juttle-client-library/dist/juttle-client-library.css';
import '../sass/main.scss';
// construct client plus views and inputs
let outriggerHost = window.location.host;
let client = new Juttle(outriggerHost);
let view = new client.View(document.getElementById('juttle-view-layout'));
let inputs = new client.Input(document.getElementById('juttle-input-groups'));
let errors = new client.Errors(document.getElementById('error-view'));
let renderError = errors.render.bind(errors);
let juttleSourceEl = document.getElementById('juttle-source');
let currentBundle;
let parsed = url.parse(window.location.href, true);
let initBundle = (bundle) => {
ReactDOM.render(, juttleSourceEl);
currentBundle = bundle;
client.describe(bundle)
.then((desc) => {
// if we have no inputs go ahead and run
if (desc.inputs.length === 0) {
return view.run(bundle)
.then(function(jobEvents) {
jobEvents.on('error', function(err) {
errors.render(err);
});
jobEvents.on('warning', function(warning) {
return function(req, res, next) {
var config = req.superstatic;
var trailingSlashBehavior = config.trailingSlash;
var parsedUrl = url.parse(req.url);
var pathname = pathutils.normalizeMultiSlashes(parsedUrl.pathname);
var search = parsedUrl.search || '';
var cleanUrlRules = !!_.get(req, 'superstatic.cleanUrls');
// Exact file always wins.
return res.superstatic.provider(req, pathname).then(function(result) {
if (result) {
// If we are using cleanURLs, we'll trim off any `.html` (or `/index.html`), if it exists.
if (cleanUrlRules) {
if (_.endsWith(pathname, '.html')) {
var redirPath = pathutils.removeTrailingString(pathname, '.html');
if (_.endsWith(redirPath, '/index')) {
redirPath = pathutils.removeTrailingString(redirPath, '/index');
}
// But if we need to keep the trailing slashes, we will do so.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
* */
import Jquery from 'jquery';
import Terms from './terms';
const fup = require("fast-url-parser");
fup.queryString = require("querystringparser");
/*
* Private : Error Handler (Customized)
* */
// 1. ValidationError - warn users of wrong values.
function ValidationError() {
let temp = Error.apply(this, arguments);
temp.name = this.name = 'ValidationError';
this.message = temp.message;
if (Object.defineProperty) {
// getter for more optimize goodness
Object.defineProperty(this, 'stack', {
getUrl(data) {
let url = _.find(_.get(data, 'urls'), {type: 'detail'}).url;
// Urls targeting /comics/characters are not interesting at all
if (url.match(/comics\/characters/)) {
return null;
}
let parsedUrl = URL.parse(url, true);
parsedUrl.search = null;
parsedUrl.query = null;
return URL.format(parsedUrl);
}
};
function redirectAsCleanUrl (req, res) {
var pathname = url.parse(req.url).pathname;
var query = qs.stringify(req.query);
var redirectUrl = (isDirectoryIndexFile(pathname, req.config.index))
? path.dirname(pathname)
: path.join('/', path.dirname(pathname), path.basename(pathname.split('?')[0], '.html'));
redirectUrl += (query) ? '?' + query : '';
res.writeHead(301, { Location: redirectUrl });
res.end();
}
import url from 'fast-url-parser';
import defaultConfig from '../DefaultConfig';
url.queryString = require('querystringparser');
class Query
{
constructor()
{
this.parseQuery();
}
init(config)
{
if (!this.config)
{
this.config = config ? config : defaultConfig;
}
}
parseQuery()
{
parseQuery()
{
const parsed = url.parse(window.location.search, true);
for (const key in parsed.query)
{
if (parsed.query[key] === 'true')
{
this[key] = true;
}
else if (parsed.query[key] === 'false')
{
this[key] = false;
}
else
{
this[key] = JSON.parse(parsed.query[key]);
}
}
return function (req, res, next) {
var pathname = url.parse(req.url).pathname;
query()(req, res, function (err) {
if (err) {
return next(err);
}
isDirectory(function(isDir) {
isDirectoryIndex(function(isDirIndex) {
if (isDir && !isDirIndex) {
return next();
}
fileExists(function(fExist) {
var hasTrailSlash = hasTrailingSlash();