Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const resolve = require('path').resolve
const { Nuxt, Builder } = require('nuxt-edge')
// 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
module.exports = function (req, res) {
nuxt.render(req, res)
}
const dispatch = require('micro-route/dispatch')
const { Nuxt, Builder } = require('nuxt-edge')
// Require nuxt config
const config = require('../nuxt.config.js')
// Create a new nuxt instance
const nuxt = new Nuxt(config)
// Enable live build & reloading on dev
if (nuxt.options.dev) {
new Builder(nuxt).build()
}
module.exports = async (req, res) => {
await dispatch()
.dispatch('*', ['GET'], (req, res) => nuxt.render(req, res))(req, res)
}
before(async () => {
nuxtConfig.typescript = {
cache: true,
thread: true,
checker: false,
loader: { tsconfig: resolve('.', 'tsconfig.default.json') },
};
nuxt = new Nuxt(nuxtConfig);
await new Builder(nuxt).build();
nuxt.listen(4000);
});
async function setupNuxt (config) {
const nuxt = new Nuxt({
...defaultConfig,
...config,
_ready: false
})
jest.spyOn(nuxt.moduleContainer, 'addTemplate')
await nuxt.ready()
const builder = new Builder(nuxt)
nuxt.builder = builder
return nuxt
}
async function setupMockNuxt (config) {
const nuxt = new Nuxt({
...defaultConfig,
...config,
_ready: false
})
nuxt.moduleContainer.addTemplate = jest.fn(nuxt.moduleContainer.addTemplate)
await nuxt.ready()
const builder = new Builder(nuxt)
await builder.validatePages()
await builder.generateRoutesAndFiles()
nuxt.builder = builder
return nuxt
}