Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const commonBefore = (nuxtentConfig, config = {}) => async () => {
const mergedConfig = {
...baseConfig(nuxtentConfig),
...config
}
// Build a fresh nuxt
nuxt = new Nuxt(mergedConfig)
await new Builder(nuxt).build()
await nuxt.listen(process.env.PORT)
}
const generate = (nuxtentConfig, config = {}) => async () => {
const mergedConfig = {
...baseConfig(nuxtentConfig),
...config
}
// Build a fresh nuxt
nuxt = new Nuxt(mergedConfig)
const builder = new Builder(nuxt)
const generator = new Generator(nuxt, builder)
await generator.generate()
serve()
}
const generate = async (config = {}) => {
const mergedConfig = {
...baseConfig,
...config
};
// Build a fresh nuxt
nuxt = new Nuxt(mergedConfig);
const builder = new Builder(nuxt);
generator = new Generator(nuxt, builder);
await generator.generate();
serve(true);
};
/*
** Nuxt
*/
const http = require('http')
const { Nuxt, Builder } = require('nuxt')
let config = require('./nuxt.config.js')
config.rootDir = __dirname // for electron-builder
// Init Nuxt.js
const nuxt = new Nuxt(config)
const builder = new Builder(nuxt)
const server = http.createServer(nuxt.render)
// Build only in dev mode
if (config.dev) {
builder.build().catch(err => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
})
}
// Listen the server
server.listen()
const _NUXT_URL_ = `http://localhost:${server.address().port}`
console.log(`Nuxt working on ${_NUXT_URL_}`)
/*
** Electron
app.use(nuxt.render)
app.set('port', port)
const bootstrap = () => {
server.listen(port, host)
const appName = config.manifest.name
const envText = isDevMode ? '开发模式' : '生产模式'
console.info(`${appName} ${envText}启动成功!listening on ${host}:${port}, at ${new Date().toLocaleString()}`)
// 启动扩展服务
updateGAScript()
barrageServer(io)
webrtcServer(io)
}
if (config.dev) {
new Builder(nuxt)
.build()
.then(bootstrap)
.catch((error) => {
console.error('开发模式启动失败:', error)
process.exit(1)
})
} else {
bootstrap()
}
import { resolve } from 'path'
import { Nuxt, Builder } from 'nuxt'
// Setup nuxt.js
let config = {}
try {
config = require('../../nuxt.config.js')
} catch (e) {}
config.rootDir = resolve(__dirname, '..', '..')
config.dev = process.env.NODE_ENV !== 'production'
const nuxt = new Nuxt(config)
if (config.dev) {
const builder = new Builder(nuxt)
builder.build().then(() => process.emit('nuxt:build:done'))
} else {
process.nextTick(() => process.emit('nuxt:build:done'))
}
// Add nuxt.js middleware
export default function (req, res) {
nuxt.render(req, res)
}
app.use(session({
secret: process.env.secretKey || '7CigmgctzNfojD5D3eJ7tY62axBuFICn',
resave: false,
saveUninitialized: false,
cookie: { maxAge: 60000 }
}))
// Import API Routes
app.use('/api', routes)
// Import and Set Nuxt.js options
let config = require('../nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
// Init Nuxt.js
const nuxt = new Nuxt(config)
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
builder.build()
}
// Give nuxt middleware to express
app.use(nuxt.render)
// Listen the server
// app.listen(port, host)
server.listen(port, host)
console.log('Server listening on ' + host + ':' + port) // eslint-disable-line no-console
async function start() {
// Import and Set Nuxt.js options
let config = require('../nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
// Instanciate nuxt.js
const nuxt = new Nuxt(config)
// Add nuxt.js middleware
app.use(nuxt.render)
// Listen the server
app.listen(port, host)
console.log('Server listening on ' + host + ':' + port) // eslint-disable-line no-console
}
async function start () {
config.dev = !(process.env.NODE_ENV === 'production')
const nuxt = new Nuxt(config)
app.use(nuxt.render)
app.listen(process.env.PORT, process.env.HOST)
console.log(`API listening at http://${process.env.HOST}:${process.env.PORT}/api`) // eslint-disable-line no-console
}
process.on('message', async ({ action, target }) => {
if (action !== 'build') {
console.warn('Unknown action')
process.send({ status: 'error', err: `Nuxt process: unknown action ('${action}')` })
return
}
await nuxt.ready()
// https://github.com/nuxt/nuxt.js/blob/dev/packages/builder/src/builder.js
const builder = new Builder(nuxt)
// https://github.com/nuxt/nuxt.js/blob/dev/packages/generator/src/generator.js
const generator = new Generator(nuxt, builder)
if (target === 'development') {
builder.build().then(() => {
nuxt.listen(SERVER_PORT)
process.send({ status: 'ok' })
}).catch(err => {
console.error(err)
process.send({ status: 'error', err: err.message })
})
} else {
generator.generate({ build: true, init: true }).then(({ errors }) => {
if (errors.length === 0) process.send({ status: 'ok' })
else process.send({ status: 'error', err: 'Error occurred while generating pages' })
}).catch(err => {
console.error(err)
process.send({ status: 'error', err: err.message })