Skip to content

为什么不需要入口文件了? #1

Closed
@yugasun

Description

@yugasun

在上一个版本中,使用此组件,用户需要在项目根目录新增 sls.js 文件,现在组件帮忙处理了,所以不需要用户处理了。默认 sls.js 代码如下:

const express = require('express')
const next = require('next')
const pkg = require('./package.json')

const app = next({ dev: false })
const handle = app.getRequestHandler()

async function createServer() {
  await app.prepare()
  const server = express()

  server.all('*', (req, res) => {
    return handle(req, res)
  })

  // define binary type for response
  // if includes, will return base64 encoded, very useful for images
  server.binaryTypes = pkg.binaryTypes || ['*/*']

  return server
}

module.exports = createServer

当然,如果需要自定义路由服务,可以在项目根目录下创建 sls.js 文件,进行自定义。

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions