|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import Koa from 'koa'
|
|
|
|
|
import koaServe from 'koa-static'
|
|
|
|
|
import http from 'http'
|
|
|
|
|
import sirv from 'sirv'
|
|
|
|
|
import { resolveConfig } from '../config'
|
|
|
|
|
|
|
|
|
|
export interface ServeOptions {
|
|
|
|
@ -11,11 +11,8 @@ export async function serve(options: ServeOptions = {}) {
|
|
|
|
|
const port = options.port !== undefined ? options.port : 3000
|
|
|
|
|
const site = await resolveConfig(options.root)
|
|
|
|
|
|
|
|
|
|
const app = new Koa()
|
|
|
|
|
|
|
|
|
|
app.use(koaServe(site.outDir))
|
|
|
|
|
|
|
|
|
|
app.listen(port)
|
|
|
|
|
|
|
|
|
|
console.log(`listening at http://localhost:${port}`)
|
|
|
|
|
const server = http.createServer(sirv(site.outDir, { dev: true, etag: true }))
|
|
|
|
|
server.listen(port, () => {
|
|
|
|
|
console.log(`listening at http://localhost:${port}`)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|