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)
}
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()
}
async function start() {
// Instantiate nuxt.js
const nuxt = new Nuxt(config)
// Build in development
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
}
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)
})
})
})
async function start() {
// Instantiate nuxt.js
const nuxt = new Nuxt(nuxtConfig)
const {
host = process.env.HOST || '127.0.0.1',
port = process.env.PORT || 3000
} = nuxt.options.server
// Build in development
if (nuxtConfig.dev) {
const builder = new Builder(nuxt)
await builder.build()
} else {
await nuxt.ready()
}
app.use(koaBody({
formidable:{
uploadDir: config.uploadDir,
maxFileSize: 10*1024*1024*1024 // 10G
},
multipart: true,
parsedMethods: ['POST', 'DELETE', 'PATCH']
}));
router.use('/api', api.routes(), api.allowedMethods())
app.use(router.routes()).use(router.allowedMethods())
async function start() {
// Init Nuxt.js
const nuxt = new Nuxt(config)
const {
host = process.env.HOST || '127.0.0.1',
port = process.env.PORT || 3000
} = nuxt.options.server
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
}
// Give nuxt middleware to express
app.use(nuxt.render)
// Listen the server
app.listen(port, host)
consola.ready({
message: `Server listening on http://${host}:${port}`,
badge: true
})
}
start()
app.use(universalAnalytics.middleware(process.env.GA_ID, {cookieName: '_ga'}));
app.use(bodyParser());
app.use(logReqPerf);
const server = http.Server(app);
const io = require('socket.io')(server);
app.set('socketio', io);
// Init Nuxt.js
const nuxt = new Nuxt(config)
const {host, port} = nuxt.options.server
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
} else {
await nuxt.ready()
}
await mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true, dbName: process.env.MONGODB_DB} );
app.use(function (req, res, next) {
apiLogger.debug('req.originalUrl:', req.originalUrl);
apiLogger.debug('req.params:', req.params);
apiLogger.debug('req.query:', req.query);
next();
});
if (useOauth) setupAuthApi(mongoose.connection.db, app);
setupIoSocketListener(mongoose.connection.db, io);
setupMediaWikiListener(mongoose.connection.db, io);
async function start() {
// Init Nuxt.js
const nuxt = new Nuxt(config);
const { host, port } = nuxt.options.server;
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt);
await builder.build();
} else {
await nuxt.ready();
}
// Give nuxt middleware to express
app.use(nuxt.render);
// Listen the server
app.listen(port, host);
consola.ready({
message: `Server listening on http://${host}:${port}`,
badge: true
});
}
start();
(async function main() {
const app = express();
const nuxt = new Nuxt({ ...require(resolve('.', 'nuxt.config.js')), dev });
app.use(compression());
app.use('/api', catRoutes);
if (dev) await new Builder(nuxt).build();
app.use(nuxt.render);
app.listen(PORT, () => console.log(`> Listening on port ${PORT}`));
})();
const start = async () => {
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
}
app.listen(port, host)
consola.ready({
message: `Server listening on http://${host}:${port}`,
badge: true
})
}
(async function main() {
if (!IS_PROD) {
await new Builder(nuxt).build()
}
app.listen(PORT)
})()