Wed Oct 24 2018
Copied to clipboard! Copy reply
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
//require("@babel/polyfill");
const Koa =  require('koa')
const { Nuxt, Builder } = require('nuxt')
const Router = require('koa-router')
const Koabody = require('koa-body')
const api = require('./api')


const app = new Koa()
const port = process.env.PORT || 3000
const config = require('../nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
const nuxt = new Nuxt(config)
const router = new Router()
const koabody = new Koabody({ multipart: false })


async function start ()
{
  if (config.dev)
  {
    const builder = new Builder(nuxt)
    await builder.build()
  }

  //
  /*
  app.use(ctx => {
    ctx.status = 200
    
    // Don't let ctx.body be response. nuxt.render will be it.
    ctx.respond = false 
    
    // koa cyx. This might be useful later on, e.g. in nuxtServerInit 
    ctx.req.ctx = ctx 
    
        
    nuxt.render(ctx.req, ctx.res)
  })
  */

  app.use(router.routes())

  router.get('/', ctx => ctx.body = "hi")
  router.get('/api/paste', api.paste.getPaste )
  router.post('/api/save', koabody, api.paste.save)
  

  console.log('port:', port);

  

  app.listen(port)
}

//start()







app.use(router.routes())

router.get('/', ctx => ctx.body = "hi")
router.get('/api/paste', api.paste.getPaste )
router.post('/api/save', koabody, api.paste.save)


console.log('port:', port);
app.listen(port)