Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nuxt/server

Package Overview
Dependencies
Maintainers
3
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxt/server - npm Package Compare versions

Comparing version 2.4.5 to 2.5.0

21

CHANGELOG.md

@@ -6,2 +6,23 @@ # Change Log

# [2.5.0](https://github.com/nuxt/nuxt.js/compare/v2.4.5...v2.5.0) (2019-03-21)
### Bug Fixes
* correct socket address in use error message ([2eb1965](https://github.com/nuxt/nuxt.js/commit/2eb1965))
* **server:** handle decodeURI error ([#5243](https://github.com/nuxt/nuxt.js/issues/5243)) ([5b7f6d7](https://github.com/nuxt/nuxt.js/commit/5b7f6d7))
* await buildDone hook ([#4955](https://github.com/nuxt/nuxt.js/issues/4955)) ([5c08db2](https://github.com/nuxt/nuxt.js/commit/5c08db2))
* not send Server-Timing header if no timing info ([d9a0b5f](https://github.com/nuxt/nuxt.js/commit/d9a0b5f))
* publicPath is not reactive in dev restarting ([#5227](https://github.com/nuxt/nuxt.js/issues/5227)) ([1fb7538](https://github.com/nuxt/nuxt.js/commit/1fb7538))
### Features
* loading screen ([#5251](https://github.com/nuxt/nuxt.js/issues/5251)) ([ef41e20](https://github.com/nuxt/nuxt.js/commit/ef41e20))
* **vue-renderer:** use async fs ([#5186](https://github.com/nuxt/nuxt.js/issues/5186)) ([d07aefa](https://github.com/nuxt/nuxt.js/commit/d07aefa))
## [2.4.4](https://github.com/nuxt/nuxt.js/compare/v2.4.3...v2.4.4) (2019-02-26)

@@ -8,0 +29,0 @@

229

dist/server.js
/*!
* @nuxt/server v2.4.5 (c) 2016-2019
* @nuxt/server v2.5.0 (c) 2016-2019

@@ -96,6 +96,6 @@ * - All the amazing contributors

/* istanbul ignore if */
if (!nuxtExists) {
const error = new Error('Could not load the nuxt app');
error.body = window.document.body.innerHTML;
window.close();
throw error

@@ -121,7 +121,14 @@ }

const context = utils.getContext(req, res);
const url = decodeURI(req.url);
res.statusCode = 200;
try {
const url = decodeURI(req.url);
res.statusCode = 200;
const result = await renderRoute(url, context);
// If result is falsy, call renderLoading
if (!result) {
await nuxt.callHook('server:nuxt:renderLoading', req, res);
return
}
await nuxt.callHook('render:route', url, result, context);

@@ -192,3 +199,2 @@ const {

} catch (err) {
/* istanbul ignore if */
if (context && context.redirected) {

@@ -199,2 +205,5 @@ consola.error(err);

if (err.name === 'URIError') {
err.statusCode = 400;
}
next(err);

@@ -212,3 +221,2 @@ }

// By default, we only preload scripts or css
/* istanbul ignore if */
if (!shouldPush && asType !== 'script' && asType !== 'style') {

@@ -262,3 +270,3 @@ return

const errorMiddleware = ({ resources, options }) => function errorMiddleware(err, req, res, next) {
const errorMiddleware = ({ resources, options }) => async function errorMiddleware(err, req, res, next) {
// ensure statusCode, message and name fields

@@ -271,7 +279,2 @@

};
const errorFull = err instanceof Error ? err : typeof err === 'string'
? new Error(err) : new Error(err.message || JSON.stringify(err));
if (err.stack) errorFull.stack = err.stack;
errorFull.name = error.name;
errorFull.statusCode = error.statusCode;

@@ -318,2 +321,12 @@ const sendResponse = (content, type = 'text/html') => {

const errorFull = err instanceof Error
? err
: typeof err === 'string'
? new Error(err)
: new Error(err.message || JSON.stringify(err));
errorFull.name = error.name;
errorFull.statusCode = error.statusCode;
errorFull.stack = err.stack || undefined;
// Show stack trace

@@ -332,8 +345,9 @@ const youch = new Youch(

if (isJson) {
youch.toJSON().then((json) => {
sendResponse(JSON.stringify(json, undefined, 2), 'text/json');
});
} else {
youch.toHTML().then(html => sendResponse(html));
const json = await youch.toJSON();
sendResponse(JSON.stringify(json, undefined, 2), 'text/json');
return
}
const html = await youch.toHTML();
sendResponse(html);
};

@@ -343,8 +357,6 @@

// Remove webpack:/// & query string from the end
const sanitizeName = name =>
name ? name.replace('webpack:///', '').split('?')[0] : null;
const sanitizeName = name => name ? name.replace('webpack:///', '').split('?')[0] : null;
frame.fileName = sanitizeName(frame.fileName);
// Return if fileName is unknown
/* istanbul ignore if */
if (!frame.fileName) {

@@ -468,11 +480,12 @@ return

if (addressInUse) {
error.message = `Address \`${this.host}:${this.port}\` is already in use.`;
}
const address = this.socket || `${this.host}:${this.port}`;
error.message = `Address \`${address}\` is already in use.`;
// Listen to a random port on dev as a fallback
if (addressInUse && this.dev && this.port !== '0') {
consola.warn(error.message);
consola.info('Trying a random port...');
this.port = '0';
return this.close().then(() => this.listen())
// Listen to a random port on dev as a fallback
if (this.dev && !this.socket && this.port !== '0') {
consola.warn(error.message);
consola.info('Trying a random port...');
this.port = '0';
return this.close().then(() => this.listen())
}
}

@@ -514,17 +527,19 @@

}
return modernBrowsers[browser.name] && semver.gte(browserVersion, modernBrowsers[browser.name])
return Boolean(modernBrowsers[browser.name] && semver.gte(browserVersion, modernBrowsers[browser.name]))
};
let detected = false;
const distinctModernModeOptions = [false, 'client', 'server'];
const detectModernBuild = ({ options, resources }) => {
if (detected === false && ![false, 'client', 'server'].includes(options.modern)) {
detected = true;
if (resources.modernManifest) {
options.modern = options.render.ssr ? 'server' : 'client';
consola.info(`Modern bundles are detected. Modern mode (${chalk.green.bold(options.modern)}) is enabled now.`);
} else {
options.modern = false;
}
if (distinctModernModeOptions.includes(options.modern)) {
return
}
if (!resources.modernManifest) {
options.modern = false;
return
}
options.modern = options.render.ssr ? 'server' : 'client';
consola.info(`Modern bundles are detected. Modern mode (${chalk.green.bold(options.modern)}) is enabled now.`);
};

@@ -537,22 +552,20 @@

}
return socket.isModernBrowser
};
const setModernMode = (req, options) => {
const { socket = {} } = req;
const { isModernBrowser } = socket;
if (options.modern === 'server') {
req.modernMode = isModernBrowser;
const createModernMiddleware = ({ context }) => {
let detected = false;
return (req, res, next) => {
if (!detected) {
detectModernBuild(context);
detected = true;
}
if (context.options.modern !== false) {
req.modernMode = detectModernBrowser(req);
}
next();
}
if (options.dev && !!options.modern) {
req.devModernMode = isModernBrowser;
}
};
const createModernMiddleware = ({ context }) => (req, res, next) => {
detectModernBuild(context);
detectModernBrowser(req);
setModernMode(req, context.options);
next();
};
const createTimingMiddleware = options => (req, res, next) => {

@@ -571,9 +584,12 @@ if (res.timing) {

res.setHeader(
'Server-Timing',
[]
.concat(res.getHeader('Server-Timing') || [])
.concat(res.timing.headers)
.join(', ')
);
if (res.timing.headers.length > 0) {
res.setHeader(
'Server-Timing',
[]
.concat(res.getHeader('Server-Timing') || [])
.concat(res.timing.headers)
.join(', ')
);
}
res.timing.clear();
});

@@ -592,3 +608,5 @@

const time = super.end(...args);
this.headers.push(this.formatHeader(time));
if (time) {
this.headers.push(this.formatHeader(time));
}
return time

@@ -622,6 +640,2 @@ }

// Will be available on dev
this.devMiddleware = null;
this.hotMiddleware = null;
// Will be set after listen

@@ -635,5 +649,17 @@ this.listeners = [];

this.nuxt.hook('close', () => this.close());
// devMiddleware placeholder
if (this.options.dev) {
this.nuxt.hook('server:devMiddleware', (devMiddleware) => {
this.devMiddleware = devMiddleware;
});
}
}
async ready() {
if (this._readyCalled) {
return this
}
this._readyCalled = true;
await this.nuxt.callHook('render:before', this, this.options.render);

@@ -653,2 +679,4 @@

await this.nuxt.callHook('render:done', this);
return this
}

@@ -677,29 +705,2 @@

const modernMiddleware = createModernMiddleware({
context: this.renderer.context
});
// Add webpack middleware support only for development
if (this.options.dev) {
this.useMiddleware(modernMiddleware);
this.useMiddleware(async (req, res, next) => {
const name = req.devModernMode ? 'modern' : 'client';
if (this.devMiddleware && this.devMiddleware[name]) {
await this.devMiddleware[name](req, res);
}
if (this.hotMiddleware && this.hotMiddleware[name]) {
await this.hotMiddleware[name](req, res);
}
next();
});
}
// open in editor for debug mode only
if (this.options.debug && this.options.dev) {
this.useMiddleware({
path: '__open-in-editor',
handler: launchMiddleware(this.options.editor)
});
}
// For serving static/ files to /

@@ -724,5 +725,26 @@ const staticMiddleware = serveStatic(

});
this.useMiddleware(modernMiddleware);
}
this.useMiddleware(createModernMiddleware({
context: this.renderer.context
}));
// Dev middleware
if (this.options.dev) {
this.useMiddleware((req, res, next) => {
if (!this.devMiddleware) {
return next()
}
this.devMiddleware(req, res, next);
});
// open in editor for debug mode only
if (this.options.debug) {
this.useMiddleware({
path: '__open-in-editor',
handler: launchMiddleware(this.options.editor)
});
}
}
// Add user provided middleware

@@ -733,5 +755,6 @@ for (const m of this.options.serverMiddleware) {

// Graceful 404 error handler
const { fallback } = this.options.render;
if (fallback) {
// Graceful 404 errors for dist files
// Dist files
if (fallback.dist) {

@@ -744,3 +767,3 @@ this.useMiddleware({

// Graceful 404 errors for other paths
// Other paths
if (fallback.static) {

@@ -762,10 +785,6 @@ this.useMiddleware({

// Error middleware for errors that occurred in middleware that declared above
// Middleware should exactly take 4 arguments
// https://github.com/senchalabs/connect#error-middleware
// Apply errorMiddleware from modules first
await this.nuxt.callHook('render:errorMiddleware', this.app);
// Apply errorMiddleware from Nuxt
// Error middleware for errors that occurred in middleware that declared above
this.useMiddleware(errorMiddleware({

@@ -830,2 +849,5 @@ resources: this.resources,

async listen(port, host, socket) {
// Ensure nuxt is ready
await this.nuxt.ready();
// Create a new listener

@@ -856,5 +878,4 @@ const listener = new Listener({

for (const listener of this.listeners) {
await listener.close();
}
await Promise.all(this.listeners.map(l => l.close()));
this.listeners = [];

@@ -875,3 +896,3 @@

exports.Listener = Listener;
exports.Server = Server;
exports.Listener = Listener;
{
"name": "@nuxt/server",
"version": "2.4.5",
"version": "2.5.0",
"repository": "nuxt/nuxt.js",

@@ -11,9 +11,9 @@ "license": "MIT",

"dependencies": {
"@nuxt/config": "2.4.5",
"@nuxt/utils": "2.4.5",
"@nuxt/config": "2.5.0",
"@nuxt/utils": "2.5.0",
"@nuxtjs/youch": "^4.2.3",
"chalk": "^2.4.2",
"compression": "^1.7.3",
"compression": "^1.7.4",
"connect": "^3.6.6",
"consola": "^2.3.2",
"consola": "^2.5.7",
"etag": "^1.8.1",

@@ -24,6 +24,6 @@ "fresh": "^0.5.2",

"launch-editor-middleware": "^2.2.1",
"on-headers": "^1.0.1",
"on-headers": "^1.0.2",
"pify": "^4.0.1",
"semver": "^5.6.0",
"serve-placeholder": "^1.1.1",
"serve-placeholder": "^1.2.1",
"serve-static": "^1.13.2",

@@ -30,0 +30,0 @@ "server-destroy": "^1.0.1",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc