1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

next-server (#5357)

This commit is contained in:
Tim Neutkens 2018-10-02 00:55:31 +02:00 committed by GitHub
parent 532351ebcf
commit 82d56e063a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
78 changed files with 313 additions and 140 deletions

View file

@ -0,0 +1 @@
module.exports = require('./dist/lib/asset')

View file

@ -0,0 +1,17 @@
module.exports = {
'presets': [
'@babel/preset-env',
'@babel/preset-react',
'@babel/preset-flow'
],
'plugins': [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-class-properties',
['@babel/plugin-transform-runtime', {
'corejs': 2
}],
['babel-plugin-transform-define', {
'process.env.NEXT_VERSION': require('./package.json').version
}]
]
}

View file

@ -0,0 +1 @@
module.exports = require('./dist/lib/runtime-config')

View file

@ -0,0 +1 @@
module.exports = require('./dist/lib/constants')

View file

@ -0,0 +1 @@
module.exports = require('./dist/lib/dynamic')

View file

@ -0,0 +1 @@
module.exports = require('./dist/lib/head')

View file

@ -0,0 +1,27 @@
import {join} from 'path'
export const PHASE_EXPORT = 'phase-export'
export const PHASE_PRODUCTION_BUILD = 'phase-production-build'
export const PHASE_PRODUCTION_SERVER = 'phase-production-server'
export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server'
export const PAGES_MANIFEST = 'pages-manifest.json'
export const BUILD_MANIFEST = 'build-manifest.json'
export const REACT_LOADABLE_MANIFEST = 'react-loadable-manifest.json'
export const SERVER_DIRECTORY = 'server'
export const CONFIG_FILE = 'next.config.js'
export const BUILD_ID_FILE = 'BUILD_ID'
export const BLOCKED_PAGES = [
'/_document',
'/_app',
'/_error'
]
export const CLIENT_STATIC_FILES_PATH = 'static'
export const CLIENT_STATIC_FILES_RUNTIME = 'runtime'
export const CLIENT_STATIC_FILES_RUNTIME_PATH = `${CLIENT_STATIC_FILES_PATH}/${CLIENT_STATIC_FILES_RUNTIME}`
// static/runtime/main.js
export const CLIENT_STATIC_FILES_RUNTIME_MAIN = `${CLIENT_STATIC_FILES_RUNTIME_PATH}/main.js`
// static/runtime/webpack.js
export const CLIENT_STATIC_FILES_RUNTIME_WEBPACK = `${CLIENT_STATIC_FILES_RUNTIME_PATH}/webpack.js`
// matches static/<buildid>/pages/<page>.js
export const IS_BUNDLED_PAGE_REGEX = /^static[/\\][^/\\]+[/\\]pages.*\.js$/
// matches static/<buildid>/pages/:page*.js
export const ROUTE_NAME_REGEX = /^static[/\\][^/\\]+[/\\]pages[/\\](.*)\.js$/

View file

@ -1,7 +1,7 @@
// @flow
import React from 'react'
import ansiHTML from 'ansi-html'
import Head from './head'
import Head from 'next-server/head'
// This component is rendered through dev-error-overlay on the client side.
// On the server side it's rendered directly

View file

@ -4,7 +4,7 @@ import { resolve, format, parse } from 'url'
import React, { Component, Children } from 'react'
import PropTypes from 'prop-types'
import Router, { _rewriteUrlForNextExport } from './router'
import { execOnce, getLocationOrigin } from './utils'
import {execOnce, getLocationOrigin} from './utils'
function isLocal (href) {
const url = parse(href, false, true)

View file

@ -8,6 +8,17 @@ export function execOnce (fn) {
}
}
export function getLocationOrigin () {
const { protocol, hostname, port } = window.location
return `${protocol}//${hostname}${port ? ':' + port : ''}`
}
export function getURL () {
const { href } = window.location
const origin = getLocationOrigin()
return href.substring(origin.length)
}
export function getDisplayName (Component) {
if (typeof Component === 'string') {
return Component
@ -45,14 +56,3 @@ export async function loadGetInitialProps (Component, ctx) {
return props
}
export function getLocationOrigin () {
const { protocol, hostname, port } = window.location
return `${protocol}//${hostname}${port ? ':' + port : ''}`
}
export function getURL () {
const { href } = window.location
const origin = getLocationOrigin()
return href.substring(origin.length)
}

View file

@ -0,0 +1 @@
module.exports = require('./dist/lib/link')

View file

@ -0,0 +1 @@
module.exports = require('./dist/server/config')

View file

@ -0,0 +1,45 @@
{
"name": "next-server",
"version": "7.0.1",
"main": "./dist/server/next-server.js",
"scripts": {
"build": "taskr",
"release": "taskr release",
"prepublish": "npm run release"
},
"taskr": {
"requires": [
"./taskfile-babel.js"
]
},
"dependencies": {
"find-up": "3.0.0",
"http-errors": "1.6.2",
"path-to-regexp": "2.1.0",
"url": "0.11.0",
"ansi-html": "0.0.7",
"prop-types": "15.6.2",
"send": "0.16.1",
"styled-jsx": "3.1.0",
"etag": "1.8.1",
"fresh": "0.5.2",
"htmlescape": "1.1.1"
},
"peerDependencies": {
"react": "^16.0.0",
"react-dom": "^16.0.0"
},
"devDependencies": {
"@babel/core": "7.1.2",
"@babel/plugin-proposal-class-properties": "7.1.0",
"@babel/plugin-proposal-object-rest-spread": "7.0.0",
"@babel/plugin-syntax-dynamic-import": "7.0.0",
"@babel/plugin-transform-runtime": "7.1.0",
"@babel/preset-env": "7.1.0",
"@babel/preset-react": "7.0.0",
"@babel/runtime": "7.1.2",
"@babel/runtime-corejs2": "7.1.2",
"@taskr/clear": "1.1.0",
"@taskr/watch": "1.1.0"
}
}

View file

@ -0,0 +1 @@
module.exports = require('./dist/lib/router')

View file

@ -1,6 +1,6 @@
// @flow
import findUp from 'find-up'
import {CONFIG_FILE} from '../lib/constants'
import {CONFIG_FILE} from 'next-server/constants'
type WebpackConfig = *

View file

@ -11,8 +11,8 @@ import {
} from './render'
import Router, {route} from './router'
import { isInternalUrl } from './utils'
import loadConfig from './config'
import {PHASE_PRODUCTION_SERVER, BLOCKED_PAGES, BUILD_ID_FILE, CLIENT_STATIC_FILES_PATH, CLIENT_STATIC_FILES_RUNTIME} from '../lib/constants'
import loadConfig from 'next-server/next-config'
import {PHASE_PRODUCTION_SERVER, BLOCKED_PAGES, BUILD_ID_FILE, CLIENT_STATIC_FILES_PATH, CLIENT_STATIC_FILES_RUNTIME} from 'next-server/constants'
import * as asset from '../lib/asset'
import * as envConfig from '../lib/runtime-config'
import { isResSent } from '../lib/utils'

View file

@ -11,7 +11,7 @@ import Head, { defaultHead } from '../lib/head'
import ErrorDebug from '../lib/error-debug'
import Loadable from '../lib/loadable'
import LoadableCapture from '../lib/loadable-capture'
import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH } from '../lib/constants'
import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH } from 'next-server/constants'
// Based on https://github.com/jamiebuilds/react-loadable/pull/132
function getDynamicImportBundles (manifest, moduleIds) {

View file

@ -1,5 +1,5 @@
import {join, posix} from 'path'
import {PAGES_MANIFEST, SERVER_DIRECTORY} from '../lib/constants'
import {PAGES_MANIFEST, SERVER_DIRECTORY} from 'next-server/constants'
export function pageNotFoundError (page) {
const err = new Error(`Cannot find module for page: ${page}`)

View file

@ -0,0 +1,14 @@
const internalPrefixes = [
/^\/_next\//,
/^\/static\//
]
export function isInternalUrl (url) {
for (const prefix of internalPrefixes) {
if (prefix.test(url)) {
return true
}
}
return false
}

View file

@ -0,0 +1,65 @@
// taskr babel plugin with Babel 7 support
// https://github.com/lukeed/taskr/pull/305
'use strict'
const transform = require('@babel/core').transform
const flatten = require('flatten')
const BABEL_REGEX = /(^@babel\/)(preset|plugin)-(.*)/i
function getBabels () {
const pkg = require('./package.json')
return flatten(
['devDependencies', 'dependencies'].map(s => Object.keys(pkg[s] || {}))
).filter(s => BABEL_REGEX.test(s))
}
module.exports = function (task) {
let cache
task.plugin('babel', {}, function * (file, opts) {
if (opts.preload) {
delete opts.preload
// get dependencies
cache = cache || getBabels()
// attach any deps to babel's `opts`
cache.forEach(dep => {
const segs = BABEL_REGEX.exec(dep)
const type = `${segs[2]}s`
const name = `@babel/${segs[2]}-${segs[3]}`
opts[type] = opts[type] || []
// flatten all (advanced entries are arrays)
if (flatten(opts[type]).indexOf(name) === -1) {
opts[type] = opts[type].concat(name)
}
})
}
// attach file's name
opts.filename = file.base
const output = transform(file.data, opts)
if (output.map) {
const map = `${file.base}.map`
// append `sourceMappingURL` to original file
if (opts.sourceMaps !== 'both') {
output.code += Buffer.from(`\n//# sourceMappingURL=${map}`)
}
// add sourcemap to `files` array
this._.files.push({
base: map,
dir: file.dir,
data: Buffer.from(JSON.stringify(output.map))
})
}
// update file's data
file.data = Buffer.from(output.code)
})
}

View file

@ -0,0 +1,40 @@
const notifier = require('node-notifier')
export async function bin (task, opts) {
await task.source(opts.src || 'bin/*').babel().target('dist/bin', {mode: '0755'})
notify('Compiled binaries')
}
export async function lib (task, opts) {
await task.source(opts.src || 'lib/**/*.js').babel().target('dist/lib')
notify('Compiled lib files')
}
export async function server (task, opts) {
await task.source(opts.src || 'server/**/*.js').babel().target('dist/server')
notify('Compiled server files')
}
export async function build (task) {
await task.parallel(['bin', 'server', 'lib'])
}
export default async function (task) {
await task.start('build')
await task.watch('bin/*', 'bin')
await task.watch('server/**/*.js', 'server')
await task.watch('lib/**/*.js', 'lib')
}
export async function release (task) {
await task.clear('dist').start('build')
}
// notification helper
function notify (msg) {
return notifier.notify({
title: '▲ Next',
message: msg,
icon: false
})
}

View file

@ -1 +1 @@
module.exports = require('./dist/lib/asset')
module.exports = require('next-server/asset')

View file

@ -2,7 +2,7 @@
import { join } from 'path'
import { spawn } from 'cross-spawn'
import pkg from '../../package.json'
import {CONFIG_FILE} from '../lib/constants'
import {CONFIG_FILE} from 'next-server/constants'
if (pkg.peerDependencies) {
Object.keys(pkg.peerDependencies).forEach(dependency => {

View file

@ -2,8 +2,8 @@ import { join } from 'path'
import promisify from '../lib/promisify'
import fs from 'fs'
import webpack from 'webpack'
import loadConfig from '../server/config'
import { PHASE_PRODUCTION_BUILD, BUILD_ID_FILE } from '../lib/constants'
import loadConfig from 'next-server/next-config'
import { PHASE_PRODUCTION_BUILD, BUILD_ID_FILE } from 'next-server/constants'
import getBaseWebpackConfig from './webpack'
const access = promisify(fs.access)

View file

@ -17,7 +17,8 @@ import PagesManifestPlugin from './webpack/plugins/pages-manifest-plugin'
import BuildManifestPlugin from './webpack/plugins/build-manifest-plugin'
import ChunkNamesPlugin from './webpack/plugins/chunk-names-plugin'
import { ReactLoadablePlugin } from './webpack/plugins/react-loadable-plugin'
import {SERVER_DIRECTORY, NEXT_PROJECT_ROOT, NEXT_PROJECT_ROOT_NODE_MODULES, NEXT_PROJECT_ROOT_DIST, DEFAULT_PAGES_DIR, REACT_LOADABLE_MANIFEST, CLIENT_STATIC_FILES_RUNTIME_WEBPACK, CLIENT_STATIC_FILES_RUNTIME_MAIN} from '../lib/constants'
import {SERVER_DIRECTORY, REACT_LOADABLE_MANIFEST, CLIENT_STATIC_FILES_RUNTIME_WEBPACK, CLIENT_STATIC_FILES_RUNTIME_MAIN} from 'next-server/constants'
import {NEXT_PROJECT_ROOT, NEXT_PROJECT_ROOT_NODE_MODULES, NEXT_PROJECT_ROOT_DIST, DEFAULT_PAGES_DIR} from '../lib/constants'
import AutoDllPlugin from 'autodll-webpack-plugin'
import TerserPlugin from 'terser-webpack-plugin'

View file

@ -1,6 +1,6 @@
// @flow
import { RawSource } from 'webpack-sources'
import {BUILD_MANIFEST, ROUTE_NAME_REGEX, IS_BUNDLED_PAGE_REGEX, CLIENT_STATIC_FILES_RUNTIME_MAIN} from '../../../lib/constants'
import {BUILD_MANIFEST, ROUTE_NAME_REGEX, IS_BUNDLED_PAGE_REGEX, CLIENT_STATIC_FILES_RUNTIME_MAIN} from 'next-server/constants'
// This plugin creates a build-manifest.json for all assets that are being output
// It has a mapping of "entry" filename to real filename. Because the real filename can be hashed in production

View file

@ -1,7 +1,7 @@
import webpack from 'webpack'
import { RawSource } from 'webpack-sources'
import { join, relative, dirname } from 'path'
import {IS_BUNDLED_PAGE_REGEX} from '../../../lib/constants'
import {IS_BUNDLED_PAGE_REGEX} from 'next-server/constants'
const SSR_MODULE_CACHE_FILENAME = 'ssr-module-cache.js'

View file

@ -1,6 +1,6 @@
// @flow
import { RawSource } from 'webpack-sources'
import {PAGES_MANIFEST, ROUTE_NAME_REGEX} from '../../../lib/constants'
import {PAGES_MANIFEST, ROUTE_NAME_REGEX} from 'next-server/constants'
// This plugin creates a pages-manifest.json from page entrypoints.
// This is used for mapping paths like `/` to `.next/server/static/<buildid>/pages/index.js` when doing SSR

View file

@ -3,7 +3,7 @@ import { ConcatSource } from 'webpack-sources'
import {
IS_BUNDLED_PAGE_REGEX,
ROUTE_NAME_REGEX
} from '../../../lib/constants'
} from 'next-server/constants'
export default class PagesPlugin {
apply (compiler: any) {

View file

@ -2,7 +2,7 @@
import { join } from 'path'
import promisify from '../../../lib/promisify'
import fs from 'fs'
import { IS_BUNDLED_PAGE_REGEX } from '../../../lib/constants'
import { IS_BUNDLED_PAGE_REGEX } from 'next-server/constants'
const unlink = promisify(fs.unlink)

View file

@ -1,7 +1,7 @@
import path from 'path'
import promisify from '../../lib/promisify'
import globModule from 'glob'
import {CLIENT_STATIC_FILES_PATH} from '../../lib/constants'
import {CLIENT_STATIC_FILES_PATH} from 'next-server/constants'
const glob = promisify(globModule)

View file

@ -1,14 +1,14 @@
import React from 'react'
import ReactDOM from 'react-dom'
import HeadManager from './head-manager'
import { createRouter } from '../lib/router'
import EventEmitter from '../lib/EventEmitter'
import { loadGetInitialProps, getURL } from '../lib/utils'
import { createRouter } from 'next-server/dist/lib/router'
import EventEmitter from 'next-server/dist/lib/EventEmitter'
import {loadGetInitialProps, getURL} from 'next-server/dist/lib/utils'
import PageLoader from '../lib/page-loader'
import * as asset from '../lib/asset'
import * as envConfig from '../lib/runtime-config'
import * as asset from 'next-server/asset'
import * as envConfig from 'next-server/config'
import ErrorBoundary from './error-boundary'
import Loadable from '../lib/loadable'
import Loadable from 'next-server/dist/lib/loadable'
// Polyfill Promise globally
// This is needed because Webpack's dynamic loading(common chunks) code

View file

@ -1,6 +1,6 @@
/* global location */
import Router from '../lib/router'
import Router from 'next-server/router'
import fetch from 'unfetch'
export default ({assetPrefix}) => {

View file

@ -1,6 +1,6 @@
import 'event-source-polyfill'
import connect from './dev-error-overlay/hot-dev-client'
import Router from '../lib/router'
import Router from 'next-server/router'
const handlers = {
reload (route) {

View file

@ -1 +1 @@
module.exports = require('./dist/lib/runtime-config')
module.exports = require('next-server/config')

View file

@ -1 +1 @@
module.exports = require('./dist/lib/constants')
module.exports = require('next-server/constants')

View file

@ -1 +1 @@
module.exports = require('./dist/lib/dynamic')
module.exports = require('next-server/dynamic')

View file

@ -3,11 +3,11 @@ import cp from 'recursive-copy'
import mkdirp from 'mkdirp-then'
import { extname, resolve, join, dirname, sep } from 'path'
import { existsSync, readFileSync, writeFileSync } from 'fs'
import loadConfig from '../server/config'
import {PHASE_EXPORT, SERVER_DIRECTORY, PAGES_MANIFEST, CONFIG_FILE, BUILD_ID_FILE, CLIENT_STATIC_FILES_PATH} from '../lib/constants'
import { renderToHTML } from '../server/render'
import { setAssetPrefix } from '../lib/asset'
import * as envConfig from '../lib/runtime-config'
import loadConfig from 'next-server/next-config'
import {PHASE_EXPORT, SERVER_DIRECTORY, PAGES_MANIFEST, CONFIG_FILE, BUILD_ID_FILE, CLIENT_STATIC_FILES_PATH} from 'next-server/constants'
import { renderToHTML } from 'next-server/dist/server/render'
import { setAssetPrefix } from 'next-server/asset'
import * as envConfig from 'next-server/config'
export default async function (dir, options, configuration) {
function log (message) {

View file

@ -1 +1 @@
module.exports = require('./dist/lib/head')
module.exports = require('next-server/head')

View file

@ -1,7 +1,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { execOnce, loadGetInitialProps } from './utils'
import { makePublicRouterInstance } from './router'
import { execOnce, loadGetInitialProps } from 'next-server/dist/lib/utils'
import { makePublicRouterInstance } from 'next-server/router'
export default class App extends Component {
static childContextTypes = {

View file

@ -1,31 +1,5 @@
import {join} from 'path'
export const PHASE_EXPORT = 'phase-export'
export const PHASE_PRODUCTION_BUILD = 'phase-production-build'
export const PHASE_PRODUCTION_SERVER = 'phase-production-server'
export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server'
export const PAGES_MANIFEST = 'pages-manifest.json'
export const BUILD_MANIFEST = 'build-manifest.json'
export const REACT_LOADABLE_MANIFEST = 'react-loadable-manifest.json'
export const SERVER_DIRECTORY = 'server'
export const CONFIG_FILE = 'next.config.js'
export const BUILD_ID_FILE = 'BUILD_ID'
export const BLOCKED_PAGES = [
'/_document',
'/_app',
'/_error'
]
// matches static/<buildid>/pages/<page>.js
export const IS_BUNDLED_PAGE_REGEX = /^static[/\\][^/\\]+[/\\]pages.*\.js$/
// matches static/<buildid>/pages/:page*.js
export const ROUTE_NAME_REGEX = /^static[/\\][^/\\]+[/\\]pages[/\\](.*)\.js$/
export const NEXT_PROJECT_ROOT = join(__dirname, '..', '..')
export const NEXT_PROJECT_ROOT_DIST = join(NEXT_PROJECT_ROOT, 'dist')
export const NEXT_PROJECT_ROOT_NODE_MODULES = join(NEXT_PROJECT_ROOT, 'node_modules')
export const DEFAULT_PAGES_DIR = join(NEXT_PROJECT_ROOT_DIST, 'pages')
export const CLIENT_STATIC_FILES_PATH = 'static'
export const CLIENT_STATIC_FILES_RUNTIME = 'runtime'
export const CLIENT_STATIC_FILES_RUNTIME_PATH = `${CLIENT_STATIC_FILES_PATH}/${CLIENT_STATIC_FILES_RUNTIME}`
// static/runtime/main.js
export const CLIENT_STATIC_FILES_RUNTIME_MAIN = `${CLIENT_STATIC_FILES_RUNTIME_PATH}/main.js`
// static/runtime/webpack.js
export const CLIENT_STATIC_FILES_RUNTIME_WEBPACK = `${CLIENT_STATIC_FILES_RUNTIME_PATH}/webpack.js`

View file

@ -1,7 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import HTTPStatus from 'http-status'
import Head from './head'
import Head from 'next-server/head'
export default class Error extends React.Component {
static getInitialProps ({ res, err }) {

View file

@ -1,5 +1,5 @@
/* global window, document */
import EventEmitter from './EventEmitter'
import EventEmitter from 'next-server/dist/lib/EventEmitter'
const webpackModule = module

View file

@ -1 +1 @@
module.exports = require('./dist/lib/link')
module.exports = require('next-server/link')

View file

@ -47,6 +47,7 @@
]
},
"dependencies": {
"next-server": "7.0.1",
"@babel/core": "7.1.2",
"@babel/plugin-proposal-class-properties": "7.1.0",
"@babel/plugin-proposal-object-rest-spread": "7.0.0",

View file

@ -1 +1 @@
module.exports = require('./dist/lib/router')
module.exports = require('next-server/router')

View file

@ -6,14 +6,31 @@ import del from 'del'
import onDemandEntryHandler, {normalizePage} from './on-demand-entry-handler'
import webpack from 'webpack'
import getBaseWebpackConfig from '../build/webpack'
import {
addCorsSupport
} from './utils'
import {IS_BUNDLED_PAGE_REGEX, ROUTE_NAME_REGEX, BLOCKED_PAGES, CLIENT_STATIC_FILES_PATH} from '../lib/constants'
import pathMatch from './lib/path-match'
import {renderScriptError} from './render'
import {IS_BUNDLED_PAGE_REGEX, ROUTE_NAME_REGEX, BLOCKED_PAGES, CLIENT_STATIC_FILES_PATH} from 'next-server/constants'
import {route} from 'next-server/dist/server/router'
import {renderScriptError} from 'next-server/dist/server/render'
function addCorsSupport (req, res) {
if (!req.headers.origin) {
return { preflight: false }
}
res.setHeader('Access-Control-Allow-Origin', req.headers.origin)
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET')
// Based on https://github.com/primus/access-control/blob/4cf1bc0e54b086c91e6aa44fb14966fa5ef7549c/index.js#L158
if (req.headers['access-control-request-headers']) {
res.setHeader('Access-Control-Allow-Headers', req.headers['access-control-request-headers'])
}
if (req.method === 'OPTIONS') {
res.writeHead(200)
res.end()
return { preflight: true }
}
return { preflight: false }
}
const route = pathMatch()
const matchNextPageBundleRequest = route('/_next/static/:buildId/pages/:path*.js(.map)?')
// Recursively look up the issuer till it ends up at the root

View file

@ -1,8 +1,8 @@
import Server from './next-server'
import Server from 'next-server'
import { join } from 'path'
import HotReloader from './hot-reloader'
import {route} from './router'
import {PHASE_DEVELOPMENT_SERVER} from '../lib/constants'
import {route} from 'next-server/dist/server/router'
import {PHASE_DEVELOPMENT_SERVER} from 'next-server/constants'
export default class DevServer extends Server {
constructor (options) {

View file

@ -1,5 +1,5 @@
// This file is used for when users run `require('next')`
module.exports = (opts) => {
const Server = opts.dev ? require('./next-dev-server').default : require('./next-server').default
const Server = opts.dev ? require('./next-dev-server').default : require('next-server').default
return new Server(opts)
}

View file

@ -5,9 +5,9 @@ import { parse } from 'url'
import fs from 'fs'
import promisify from '../lib/promisify'
import globModule from 'glob'
import {normalizePagePath, pageNotFoundError} from './require'
import {normalizePagePath, pageNotFoundError} from 'next-server/dist/server/require'
import {createEntry} from '../build/webpack/utils'
import { ROUTE_NAME_REGEX, IS_BUNDLED_PAGE_REGEX } from '../lib/constants'
import { ROUTE_NAME_REGEX, IS_BUNDLED_PAGE_REGEX } from 'next-server/constants'
const ADDED = Symbol('added')
const BUILDING = Symbol('building')

View file

@ -1,35 +0,0 @@
const internalPrefixes = [
/^\/_next\//,
/^\/static\//
]
export function isInternalUrl (url) {
for (const prefix of internalPrefixes) {
if (prefix.test(url)) {
return true
}
}
return false
}
export function addCorsSupport (req, res) {
if (!req.headers.origin) {
return { preflight: false }
}
res.setHeader('Access-Control-Allow-Origin', req.headers.origin)
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET')
// Based on https://github.com/primus/access-control/blob/4cf1bc0e54b086c91e6aa44fb14966fa5ef7549c/index.js#L158
if (req.headers['access-control-request-headers']) {
res.setHeader('Access-Control-Allow-Headers', req.headers['access-control-request-headers'])
}
if (req.method === 'OPTIONS') {
res.writeHead(200)
res.end()
return { preflight: true }
}
return { preflight: false }
}

View file

@ -1,7 +1,7 @@
/* global describe, test, it, expect */
import cheerio from 'cheerio'
import {BUILD_MANIFEST, REACT_LOADABLE_MANIFEST} from 'next/constants'
import {BUILD_MANIFEST, REACT_LOADABLE_MANIFEST} from 'next-server/constants'
import { join } from 'path'
export default function ({ app }, suiteName, render, fetch, appPort) {

View file

@ -2,7 +2,7 @@
import { join } from 'path'
import { existsSync } from 'fs'
import {BUILD_ID_FILE} from 'next/constants'
import {BUILD_ID_FILE} from 'next-server/constants'
import {
nextServer,
nextBuild,

View file

@ -1,4 +1,4 @@
const {PHASE_DEVELOPMENT_SERVER} = require('next/constants')
const {PHASE_DEVELOPMENT_SERVER} = require('next-server/constants')
module.exports = (phase) => {
return {

View file

@ -16,7 +16,7 @@ import fetch from 'node-fetch'
import dynamicImportTests from './dynamic'
import processEnv from './process-env'
import security from './security'
import {BUILD_MANIFEST, REACT_LOADABLE_MANIFEST} from 'next/constants'
import {BUILD_MANIFEST, REACT_LOADABLE_MANIFEST} from 'next-server/constants'
const appDir = join(__dirname, '../')
let appPort

View file

@ -1,8 +1,8 @@
/* global describe, it, expect */
import {join} from 'path'
import loadConfig from 'next/dist/server/config'
import {PHASE_DEVELOPMENT_SERVER} from 'next/constants'
import loadConfig from 'next-server/next-config'
import {PHASE_DEVELOPMENT_SERVER} from 'next-server/constants'
const pathToConfig = join(__dirname, '_resolvedata', 'without-function')
const pathToConfigFn = join(__dirname, '_resolvedata', 'with-function')

View file

@ -1,8 +1,8 @@
/* global describe, it, expect */
import { join } from 'path'
import {SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH} from 'next/constants'
import requirePage, {getPagePath, normalizePagePath, pageNotFoundError} from 'next/dist/server/require'
import {SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH} from 'next-server/constants'
import requirePage, {getPagePath, normalizePagePath, pageNotFoundError} from 'next-server/dist/server/require'
const sep = '/'
const distDir = join(__dirname, '_resolvedata')

1
test/node_modules/next generated vendored
View file

@ -1 +0,0 @@
../../packages/next

View file

@ -1,5 +1,5 @@
/* global describe, it, expect */
import EventEmitter from 'next/dist/lib/EventEmitter'
import EventEmitter from 'next-server/dist/lib/EventEmitter'
describe('EventEmitter', () => {
describe('With listeners', () => {

View file

@ -1,6 +1,6 @@
/* global describe, it, expect */
import { Component } from 'react'
import { getDisplayName } from 'next/dist/lib/utils'
import { getDisplayName } from 'next-server/dist/lib/utils'
describe('getDisplayName', () => {
it('gets the proper display name of a component', () => {

View file

@ -1,5 +1,5 @@
/* global describe, it, expect */
import { loadGetInitialProps } from 'next/dist/lib/utils'
import { loadGetInitialProps } from 'next-server/dist/lib/utils'
describe('loadGetInitialProps', () => {
it('should throw if getInitialProps is defined as an instance method', () => {

View file

@ -1,5 +1,5 @@
/* global describe, it, expect */
import Router from 'next/dist/lib/router/router'
import Router from 'next-server/dist/lib/router/router'
class PageLoader {
constructor (options = {}) {

View file

@ -1,6 +1,6 @@
/* global describe, it, expect */
import shallowEquals from 'next/dist/lib/shallow-equals'
import shallowEquals from 'next-server/dist/lib/shallow-equals'
describe('Shallow Equals', () => {
it('should be true if both objects are the same', () => {