Skip to content

Instantly share code, notes, and snippets.

@marshallswain
Forked from silvestreh/app-index.js
Created April 3, 2017 17:46
Show Gist options
  • Save marshallswain/11516d7650d260ba3a107495b7eeddf7 to your computer and use it in GitHub Desktop.
Save marshallswain/11516d7650d260ba3a107495b7eeddf7 to your computer and use it in GitHub Desktop.
Integrate Nuxt into Feathers
// src/app.js
/**
* There's not much to do here. Just remove or comment out
* the lines that use feathers.static (the public/ directory)
*/
app.use('/', feathers.static(app.get('public'))); // Find and remove this line
# Remember to install the new dependencies
npm install --save nuxt
npm install --save-dev nodemon
// src/middleware/index.js
/**
* Add the Nuxt middleware to your Feathers app
*/
const handler = require('feathers-errors/handler');
const notFound = require('feathers-errors/not-found');
const nuxt = require('./nuxt'); // Require the middleware
module.exports = function () {
// Add your custom middleware here. Remember, that
// in Express the order matters, `notFound` and
// the error handler have to go last.
const app = this;
app.use(nuxt.render); // Use the middleware. Remember to do it before the notFound and error handler middlewares
app.use(notFound());
app.use(handler());
};
/**
* Set up Nuxt – More info at: https://nuxtjs.org/guide/configuration/
*/
const path = require('path');
module.exports = {
loading: {
color: '#92D3CE',
},
rootDir: path.resolve(__dirname),
dir: path.resolve(__dirname),
dev: process.env.NODE_ENV !== 'production',
};
// src/middleware/nuxt.js
/**
* Create the Nuxt middleware. This builds Nuxt and exports it
*/
const Nuxt = require('nuxt');
const config = require('../../nuxt.config');
const logger = require('winston');
const nuxt = new Nuxt(config);
if (config.dev) {
nuxt.build()
.then(() => process.emit('nuxt:build:done'))
.catch((error) => {
logger.error(error);
process.exit(1);
});
} else {
process.nextTick(() => process.emit('nuxt:build:done'));
}
module.exports = nuxt;
// Add new scripts for `dev` and `build` to your package.json
{
"scripts": {
"test": "npm run eslint && npm run mocha",
"eslint": "eslint src/. test/. --config .eslintrc.json",
"start": "node src/",
"build": "nuxt build",
"dev": "DEBUG=nuxt:* nodemon --watch src/ --watch config/ src/index.js",
"mocha": "mocha test/ --recursive"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment