Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yugasun opened this issue Mar 4, 2020 · 0 comments
Closed

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

yugasun opened this issue Mar 4, 2020 · 0 comments
Labels

Comments

@yugasun
Copy link
Contributor

yugasun commented Mar 4, 2020

在上一个版本中,使用此组件,用户需要在项目根目录新增 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 文件,进行自定义。

@yugasun yugasun added the FAQ label Mar 4, 2020
@yugasun yugasun changed the title 为什么不需要入口文件? 为什么不需要入口文件了? Mar 4, 2020
@yugasun yugasun pinned this issue Mar 4, 2020
@yugasun yugasun closed this as completed Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant