This repository was archived by the owner on Feb 2, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +17
-104
lines changed Expand file tree Collapse file tree 4 files changed +17
-104
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import { resolve , join } from 'path'
22
3+ import express from 'express'
4+
35import pkg from '../package.json'
46
57import createRouter from './content/api'
@@ -49,6 +51,7 @@ export default function ContentModule (moduleOpts) {
4951 componentsDir : '/components' ,
5052 buildDir : `/content` ,
5153 isStatic : userOptions . isStatic || process . env . STATIC || false ,
54+ port : process . env . PORT || process . env . npm_package_config_nuxt_port || 3000 ,
5255
5356 content : contentOptions ( userOptions . content , {
5457 page : null ,
@@ -98,10 +101,23 @@ export default function ContentModule (moduleOpts) {
98101 } )
99102
100103 // 2. Add content API
104+ const router = createRouter ( options )
101105
106+ // Add API when running `nuxt` & `nuxt build` (development and production)
102107 this . addServerMiddleware ( {
103108 path : api . serverPrefix ,
104- handler : createRouter ( options )
109+ handler : router
110+ } )
111+
112+ // Add API when running `nuxt generate`
113+ this . nuxt . plugin ( 'generator' , generator => {
114+ const app = express ( )
115+ app . use ( api . serverPrefix , router )
116+ const server = app . listen ( options . port )
117+
118+ generator . plugin ( 'generated' , ( ) => {
119+ server . close ( )
120+ } )
105121 } )
106122
107123 // 3. Add request helpers
Original file line number Diff line number Diff line change 2222 " Static"
2323 ],
2424 "license" : " MIT " ,
25- "bin" : {
26- "nuxtent" : " bin/nuxtent"
27- },
2825 "scripts" : {
2926 "#<git hooks>" : " handled by husky" ,
3027 "precommit" : " lint-staged" ,
You can’t perform that action at this time.
0 commit comments