为什么我打开首页和about都只显示ok
来源:4-12 在 Vue SSR 中实现微信 JS-SDK 权限接入
Mamier
2017-10-22
而且控制台也只显示之前的测试都没问题。就是主页和about页面访问不了。
这是我的server.js代码
import Koa from 'koa'
import { Nuxt, Builder } from 'nuxt'
import R from 'ramda'
import { resolve } from 'path'
const r = path => resolve(__dirname, path)
const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 3000
const MIDDLEWARES = ['database','router']
let config = require('../nuxt.config.js')
config.dev = !(process.env === 'production')
class Server {
constructor () {
this.app = new Koa()
this.useMiddleWares(this.app)(MIDDLEWARES)
}
useMiddleWares (app) {
return R.map(R.compose(
R.map(i => i(app)),
require,
i => `${r('./middlewares')}/${i}`
))
}
async start () {
const nuxt = await new Nuxt(config)
if (config.dev) {
const builder = new Builder(nuxt)
builder.build().catch(e => {
console.error(e)
process.exit(1)
})
}
this.app.use(async (ctx, next) => {
ctx.status = 200
ctx.req.session = ctx.session
await nuxt.render(ctx.req, ctx.res)
})
this.app.listen(port, host)
console.log('Server listening on ' + host + ':' + port)
}
}
const app = new Server()
app.start()
1回答
-
Mamier
提问者
2017-10-22
已经解决。
162018-02-02
相似问题