mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
feat: use express instead of connect
requirement of webpack-dev-middleware too
This commit is contained in:
parent
ade89f1067
commit
c0e565cbe7
@ -1,6 +1,6 @@
|
|||||||
import { promises as fs } from 'fs'
|
import { promises as fs } from 'fs'
|
||||||
import { join, extname, basename } from 'path'
|
import { join, extname, basename } from 'path'
|
||||||
import connect from 'connect'
|
import express from 'express'
|
||||||
import serveStatic from 'serve-static'
|
import serveStatic from 'serve-static'
|
||||||
import compression from 'compression'
|
import compression from 'compression'
|
||||||
import { getNuxtConfig } from 'src/config'
|
import { getNuxtConfig } from 'src/config'
|
||||||
@ -38,7 +38,7 @@ export default {
|
|||||||
if (!distStat || !distStat.isDirectory()) {
|
if (!distStat || !distStat.isDirectory()) {
|
||||||
throw new Error('Output directory `' + basename(options.generate.dir) + '/` does not exists, please run `nuxt export` before `nuxt serve`.')
|
throw new Error('Output directory `' + basename(options.generate.dir) + '/` does not exists, please run `nuxt export` before `nuxt serve`.')
|
||||||
}
|
}
|
||||||
const app = connect()
|
const app = express()
|
||||||
app.use(compression({ threshold: 0 }))
|
app.use(compression({ threshold: 0 }))
|
||||||
app.use(
|
app.use(
|
||||||
options.router.base,
|
options.router.base,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import type { WatchOptions as ChokidarWatchOptions } from 'chokidar'
|
import type { WatchOptions as ChokidarWatchOptions } from 'chokidar'
|
||||||
import type { NextHandleFunction, Server as ConnectServer } from 'connect'
|
import type express from 'express'
|
||||||
import type { configHooksT } from 'hookable/types/types'
|
import type { configHooksT } from 'hookable/types/types'
|
||||||
import ignore from 'ignore'
|
import ignore from 'ignore'
|
||||||
import capitalize from 'lodash/capitalize'
|
import capitalize from 'lodash/capitalize'
|
||||||
@ -57,13 +57,13 @@ interface NuxtHooks extends configHooksT {
|
|||||||
render?: {
|
render?: {
|
||||||
before?(renderer: any, options: any): void
|
before?(renderer: any, options: any): void
|
||||||
done?(renderer: any): void
|
done?(renderer: any): void
|
||||||
errorMiddleware?(app: ConnectServer): void
|
errorMiddleware?(app: express.Application): void
|
||||||
resourcesLoaded?(resources: any): void
|
resourcesLoaded?(resources: any): void
|
||||||
route?(url: string, result: any, context: any): void
|
route?(url: string, result: any, context: any): void
|
||||||
routeContext?(context: any): void
|
routeContext?(context: any): void
|
||||||
routeDone?(url: string, result: any, context: any): void
|
routeDone?(url: string, result: any, context: any): void
|
||||||
beforeResponse?(url: string, result: any, context: any): void
|
beforeResponse?(url: string, result: any, context: any): void
|
||||||
setupMiddleware?(app: ConnectServer): void
|
setupMiddleware?(app: express.Application): void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ interface CommonConfiguration {
|
|||||||
modules: NuxtModule[]
|
modules: NuxtModule[]
|
||||||
privateRuntimeConfig: Record<string, any> | ((env: NodeJS.ProcessEnv) => Record<string, any>)
|
privateRuntimeConfig: Record<string, any> | ((env: NodeJS.ProcessEnv) => Record<string, any>)
|
||||||
publicRuntimeConfig: Record<string, any> | ((env: NodeJS.ProcessEnv) => Record<string, any>)
|
publicRuntimeConfig: Record<string, any> | ((env: NodeJS.ProcessEnv) => Record<string, any>)
|
||||||
serverMiddleware: Array<ServerMiddleware> | Record<string, NextHandleFunction>
|
serverMiddleware: Array<ServerMiddleware> | Record<string, expr>
|
||||||
ssr: boolean
|
ssr: boolean
|
||||||
target: Target
|
target: Target
|
||||||
test: boolean
|
test: boolean
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
// TODO: Refactor @nuxt/server related options into `server.js`
|
// TODO: Refactor @nuxt/server related options into `server.js`
|
||||||
import type { ServerResponse } from 'http'
|
import type { ServerResponse, IncomingMessage } from 'http'
|
||||||
import type { Options as EtagOptions } from 'etag'
|
|
||||||
import type { IncomingMessage } from 'connect'
|
|
||||||
import type { CompressionOptions } from 'compression'
|
import type { CompressionOptions } from 'compression'
|
||||||
import type { ServeStaticOptions } from 'serve-static'
|
import type { ServeStaticOptions } from 'serve-static'
|
||||||
import type { ServerMiddleware } from './_common'
|
import type { ServerMiddleware } from './_common'
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import type { ServerResponse } from 'http'
|
import type { ServerResponse, IncomingMessage } from 'http'
|
||||||
import type { IncomingMessage } from 'connect'
|
|
||||||
|
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import onHeaders from 'on-headers'
|
import onHeaders from 'on-headers'
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { ServerResponse } from 'http'
|
import { ServerResponse, IncomingMessage } from 'http'
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import launchMiddleware from 'launch-editor-middleware'
|
import launchMiddleware from 'launch-editor-middleware'
|
||||||
import serveStatic from 'serve-static'
|
import serveStatic from 'serve-static'
|
||||||
import servePlaceholder from 'serve-placeholder'
|
import servePlaceholder from 'serve-placeholder'
|
||||||
import connect, { IncomingMessage } from 'connect'
|
import express from 'express'
|
||||||
import type { TemplateExecutor } from 'lodash'
|
import type { TemplateExecutor } from 'lodash'
|
||||||
|
|
||||||
import { Nuxt } from 'src/core'
|
import { Nuxt } from 'src/core'
|
||||||
@ -25,7 +25,7 @@ interface Manifest {
|
|||||||
async: Array<string>
|
async: Array<string>
|
||||||
}
|
}
|
||||||
|
|
||||||
type NuxtMiddleware = connect.HandleFunction & {
|
type NuxtMiddleware = express.Handler & {
|
||||||
prefix?: string,
|
prefix?: string,
|
||||||
entry?: string,
|
entry?: string,
|
||||||
_middleware?: NuxtMiddleware
|
_middleware?: NuxtMiddleware
|
||||||
@ -35,7 +35,7 @@ export default class Server {
|
|||||||
__closed?: boolean
|
__closed?: boolean
|
||||||
_readyCalled?: boolean
|
_readyCalled?: boolean
|
||||||
|
|
||||||
app: connect.Server
|
app: express.Application
|
||||||
devMiddleware: (req: IncomingMessage, res: ServerResponse, next: (err?: any) => void) => any
|
devMiddleware: (req: IncomingMessage, res: ServerResponse, next: (err?: any) => void) => any
|
||||||
listeners: Listener[]
|
listeners: Listener[]
|
||||||
nuxt: Nuxt
|
nuxt: Nuxt
|
||||||
@ -71,8 +71,8 @@ export default class Server {
|
|||||||
// Will be set after listen
|
// Will be set after listen
|
||||||
this.listeners = []
|
this.listeners = []
|
||||||
|
|
||||||
// Create new connect instance
|
// Create new express instance
|
||||||
this.app = connect()
|
this.app = express()
|
||||||
|
|
||||||
// Close hook
|
// Close hook
|
||||||
this.nuxt.hook('close', () => this.close())
|
this.nuxt.hook('close', () => this.close())
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import type { ServerResponse } from 'http'
|
import type { ServerResponse, IncomingMessage } from 'http'
|
||||||
import type { IncomingMessage } from 'connect'
|
|
||||||
|
|
||||||
import { TARGETS } from './constants'
|
import { TARGETS } from './constants'
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
import type { IncomingMessage } from 'http'
|
||||||
import { UAParser } from 'ua-parser-js'
|
import { UAParser } from 'ua-parser-js'
|
||||||
|
|
||||||
import type { SemVer } from 'semver'
|
import type { SemVer } from 'semver'
|
||||||
import type { IncomingMessage } from 'connect'
|
|
||||||
|
|
||||||
export const ModernBrowsers = {
|
export const ModernBrowsers = {
|
||||||
Edge: '16',
|
Edge: '16',
|
||||||
|
Loading…
Reference in New Issue
Block a user