Repository koa-template

renoirb

renoirb posted a new question

koa-template • 6 days ago

Document how to also make Koa match Nuxt's router.base

Assuming a project needs to have both Nuxt and Koa to answer to non-root routes, it is unclear how we can make Koa also support setting a baseUrl to something else than root / (e.g. /foo/).

Use case

Ability to support running production build to something else than root /.

// nuxt.config.js
module.exports = {
  router: {
    base: '/foo/'
  }
}

As documented in nuxt.js/…/configuration-router

Issue

Koa has no way of knowing the setting change.

TODO

  1. Setup sample repository (see renoirb/experiments-nuxt-koa-env-runtime-201806, branch rework-hare-20180619 as a starting point)
shalldie

shalldie posted a new bug report

koa-template • a month ago

bug compile error when titleTemplate is a function

Version

vue-cli

Reproduction link

https://github.com/shalldie/nuxt-koa-tpl-err

Steps to reproduce

  1. npm install

  2. npm run dev

What is expected ?

compile successfully and the title is ok.

What is actually happening?

compile error when titleTemplagte is a function

Additional comments?

after vue init nuxt-community/koa-template demo and npm intall

in nuxt.config.js, i add this:

  head: {
    title: '',
    titleTemplate: titleChunk => {
      // If undefined or blank then we don't need the hyphen
      return titleChunk ? `${titleChunk} - wqnmlgbd >_<#@!` : 'wqnmlgbd >_<#@!';
    },
  ...

when i try npm run dev, an error appears:

err.png

shalldie

shalldie posted a new question

koa-template • a month ago

compile error when titleTemplagte is a function

vue-cli version: 2.9.6

command: vue init nuxt-community/koa-template demo

in nuxt.config.js, i add this:

  head: {
    title: '',
    titleTemplate: titleChunk => {
      // If undefined or blank then we don't need the hyphen
      return titleChunk ? `${titleChunk} - wqnmlgbd >_<#@!` : 'wqnmlgbd >_<#@!';
    },
  ...

when i try npm run dev, an error appears:

image

bihaiyouhong12

bihaiyouhong12 posted a new question

koa-template • a month ago

"titleTemplate" cannot be set to a function

When I set the "head.titleTemplate" in "nuxt.config.js" to a function, and run the command "npm run dev", It throws an error:
image

alanisme

alanisme posted a new question

koa-template • 2 months ago

Why middleware return 'Promise' in `./server/index.js`? Where does 'resolve' and 'reject' come from?

app.use(async (ctx, next) => { await next() ctx.status = 200 // koa defaults to 404 when it sees that status is unset return new Promise((resolve, reject) => { ctx.res.on('close', resolve) ctx.res.on('finish', resolve) nuxt.render(ctx.req, ctx.res, promise => { // nuxt.render passes a rejected promise into callback on error. promise.then(resolve).catch(reject) }) }) })

wscj

wscj posted a new question

koa-template • 3 months ago

No parser and no filepath given

My node.js version is v8.9.4
when I run npm run dev, the console warned:
No parser and no filepath given, using 'babylon' the parser now but this will throw an error in the future. Please specify a parser or a filepath so one can be inferred.

Just a warning, ignore it ?

moedong

moedong posted a new question

koa-template • 4 months ago

SyntaxError: Unexpected token ...

When I enter “run npm dev”,Console display:

DONE Compiled successfully in 655ms 11:59:05

E:\node\koa-nuxt\node[email protected]@nuxt\lib\core\middleware\nuxt.js:72 const policies = this.options.render.csp.policies ? {…this.options.rende r.csp.policies} : null ^^^ SyntaxError: Unexpected token … at createScript (vm.js:53:10) at Object.runInThisContext (vm.js:95:10) at Module.compile (module.js:543:28)
at Object.Module.extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module.load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (E:\node\koa-nuxt\[email protected]@nuxt\lib\co
re\renderer.js:19:24)

yoyoys

yoyoys posted a new question

koa-template • 5 months ago

regeneratorRuntime is not defined

Node version: v9.5.0
Vue Cli: 2.9.3

I've just init this template by follow these steps: (alse tried by yarn)
vue init nuxt-community/koa-template nuxt-koa-test
npm install
npm run dev

and i got errors like this

 ERROR  Failed to compile with 1 errors                                                                                     

 error  in ./server/index.js

Module build failed: Error: Couldn't find preset "env" relative to directory
.....
/Users/Yoyo/github/nuxt-koa-test/build/main.js:216
}();
 ^
ReferenceError: regeneratorRuntime is not defined
    at /Users/Yoyo/github/nuxt-koa-test/build/main.js:135:46

And i tried to add a .babelrc file, like this:

{
  "presets": ["env"]
}

Then the first error message gone, but the second error still.
Is that a polyfill problem?

Thanks for help!

rlataguerra

rlataguerra posted a new question

koa-template • 6 months ago

No Generate commande

the readme inside the template talks about a npm run generate command while there is none in package.json

https://github.com/nuxt-community/koa-template/blob/master/template/README.md
https://github.com/nuxt-community/koa-template/blob/master/template/package.json

Jokcy

Jokcy posted a new question

koa-template • 7 months ago

Nuxt build restart everytime server code updated

I guess it's not a best practice when develop. Any plan to update the setup?

maodouchen

maodouchen posted a new question

koa-template • 8 months ago

build slow

image
when i change my code, it took too long time to build

1peng

1peng posted a new question

koa-template • 10 months ago

When I use ajax crossdomain request koa api,the api is the status code 404

I think these code is not work with the method OPTION.

app.use(ctx => { ctx.status = 200 // koa defaults to 404 when it sees that status is unset return new Promise((resolve, reject) => { ctx.res.on('close', resolve) ctx.res.on('finish', resolve) nuxt.render(ctx.req, ctx.res, promise => { // nuxt.render passes a rejected promise into callback on error. promise.then(resolve).catch(reject) }) }) })

k55783637

k55783637 posted a new question

koa-template • 10 months ago

How can I start the project with pm2? (on CentOS)

I execute the command: 'pm2 start ./build/main.js'
on Windows is ok
but on CentOS: It prompted service is refused

HarshaHegde1994

HarshaHegde1994 posted a new question

koa-template • a year ago

Method after nuxt.render not excute

None of the methods are getting executed after nuxt.render.

RichAyotte

RichAyotte posted a new question

koa-template • a year ago

How to disable server side babel transpilation?

How do I disable the server side babel transpiling?

It is a big performance tax to pay during development.

yarn run v1.0.2
$ backpack dev

 DONE  Compiled successfully in 1401ms                                                                                                                                15:41:50

Server listening on 127.0.0.1:3000
Build completed in 79.273s

 DONE  Compiled successfully in 79278ms                                                                                                                               15:43:17

There seems to be a frontend build followed by a backend build which takes over a minute on my 6 core / 16GB RAM system. Any insight on what's building here?

falstack

falstack posted a new question

koa-template • a year ago

Where can i set cookie?

``` javascript
app.use(async ctx => {
ctx.status = 200 // koa defaults to 404 when it sees that status is unset
// set-cookie begin
const csrf = global.$csrf
const session = global.$session
if (csrf) {
ctx.cookies.set(csrf.key, csrf.value, {
httpOnly: csrf.httpOnly,
expires: csrf.expires,
path: csrf.path,
maxAge: csrf.maxAge
})
global.$csrf = undefined
}
if (session) {
ctx.cookies.set(session.key, session.value, {
httpOnly: session.httpOnly,
expires: session.expires,
path: session.path,
maxAge: session.maxAge
})
global.$session = undefined
}
// set-cookie end
return new Promise((resolve, reject) => {
ctx.res.on('close', resolve)
ctx.res.on('finish', resolve)
nuxt.render(ctx.req, ctx.res, promise => {
// nuxt.render passes a rejected promise into callback on error.
promise.then(resolve).catch(reject)
})
})
})

it not works, maybe i need this:

javascript
ctx.res.on('ready',() => {
// set-cookie there
resolve()
})
```

how can i do?

yoyo837

yoyo837 posted a new question

koa-template • a year ago

When in hash mode, an error occurred on the non-home page refresh.

Please click here:
nuxt/nuxt.js#1579

lfyfly

lfyfly posted a new question

koa-template • a year ago

When I visit a non-existing pages, console error 404(OK)

console error
GET http://localhost:3000/not-exist 404 (OK)

why not 404 not found

benfavre

benfavre posted a new question

koa-template • a year ago

Content Available over curl but not in browser
  • Browsers (any) load forever
  • Curl can fetch the page
PatrickSR

PatrickSR posted a new question

koa-template • a year ago

TypeError: __WEBPACK_IMPORTED_MODULE_2_nuxt___default.a is not a constructor

I create new project with this template, all the step can pass, but when I run npm run dev,console display "Compiled successfully in xxxxms",and then it will show "(node:24498) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: WEBPACKIMPORTEDMODULE2nuxt_default.a is not a constructor".

My node version is v7.10.1 and vue-cli version is v2.8.2.