feat: use express instead of connect

requirement of webpack-dev-middleware too
This commit is contained in:
pooya parsa 2020-10-29 18:30:00 +01:00
parent ade89f1067
commit c0e565cbe7
7 changed files with 16 additions and 20 deletions

View File

@ -1,6 +1,6 @@
import { promises as fs } from 'fs'
import { join, extname, basename } from 'path'
import connect from 'connect'
import express from 'express'
import serveStatic from 'serve-static'
import compression from 'compression'
import { getNuxtConfig } from 'src/config'
@ -38,7 +38,7 @@ export default {
if (!distStat || !distStat.isDirectory()) {
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(
options.router.base,

View File

@ -1,6 +1,6 @@
import path from 'path'
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 ignore from 'ignore'
import capitalize from 'lodash/capitalize'
@ -57,13 +57,13 @@ interface NuxtHooks extends configHooksT {
render?: {
before?(renderer: any, options: any): void
done?(renderer: any): void
errorMiddleware?(app: ConnectServer): void
errorMiddleware?(app: express.Application): void
resourcesLoaded?(resources: any): void
route?(url: string, result: any, context: any): void
routeContext?(context: any): void
routeDone?(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[]
privateRuntimeConfig: 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
target: Target
test: boolean

View File

@ -1,7 +1,5 @@
// TODO: Refactor @nuxt/server related options into `server.js`
import type { ServerResponse } from 'http'
import type { Options as EtagOptions } from 'etag'
import type { IncomingMessage } from 'connect'
import type { ServerResponse, IncomingMessage } from 'http'
import type { CompressionOptions } from 'compression'
import type { ServeStaticOptions } from 'serve-static'
import type { ServerMiddleware } from './_common'

View File

@ -1,5 +1,4 @@
import type { ServerResponse } from 'http'
import type { IncomingMessage } from 'connect'
import type { ServerResponse, IncomingMessage } from 'http'
import consola from 'consola'
import onHeaders from 'on-headers'

View File

@ -1,10 +1,10 @@
import path from 'path'
import { ServerResponse } from 'http'
import { ServerResponse, IncomingMessage } from 'http'
import consola from 'consola'
import launchMiddleware from 'launch-editor-middleware'
import serveStatic from 'serve-static'
import servePlaceholder from 'serve-placeholder'
import connect, { IncomingMessage } from 'connect'
import express from 'express'
import type { TemplateExecutor } from 'lodash'
import { Nuxt } from 'src/core'
@ -25,7 +25,7 @@ interface Manifest {
async: Array<string>
}
type NuxtMiddleware = connect.HandleFunction & {
type NuxtMiddleware = express.Handler & {
prefix?: string,
entry?: string,
_middleware?: NuxtMiddleware
@ -35,7 +35,7 @@ export default class Server {
__closed?: boolean
_readyCalled?: boolean
app: connect.Server
app: express.Application
devMiddleware: (req: IncomingMessage, res: ServerResponse, next: (err?: any) => void) => any
listeners: Listener[]
nuxt: Nuxt
@ -71,8 +71,8 @@ export default class Server {
// Will be set after listen
this.listeners = []
// Create new connect instance
this.app = connect()
// Create new express instance
this.app = express()
// Close hook
this.nuxt.hook('close', () => this.close())

View File

@ -1,5 +1,4 @@
import type { ServerResponse } from 'http'
import type { IncomingMessage } from 'connect'
import type { ServerResponse, IncomingMessage } from 'http'
import { TARGETS } from './constants'

View File

@ -1,7 +1,7 @@
import type { IncomingMessage } from 'http'
import { UAParser } from 'ua-parser-js'
import type { SemVer } from 'semver'
import type { IncomingMessage } from 'connect'
export const ModernBrowsers = {
Edge: '16',