-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nuxt-community/master
catchup
- Loading branch information
Showing
17 changed files
with
5,457 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
The moment you start dealing with user session, you'll notice that protected routes will reject nuxt requests when running from the server. This is because when nuxt is ran from the server, the browser cookie is lost. Below is a quick middleware solution to inject the browser's cookie to your ssr axios request. | ||
|
||
## install session | ||
|
||
`npm install --save express-session` | ||
|
||
|
||
## create middleware/ssr-cookie.js | ||
|
||
```js | ||
import axios from '~plugins/axios' | ||
|
||
export default function({isServer, req}) { | ||
if (isServer) { | ||
axios.defaults.headers.common.cookie = req.headers.cookie | ||
} | ||
} | ||
``` | ||
|
||
## add middleware to nuxt.config.js | ||
|
||
```js | ||
router: { | ||
middleware: ['ssr-cookie'] | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ npm-debug.log | |
|
||
# Nuxt generate | ||
dist | ||
|
||
# Backpack build | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
webpack: (config, options, webpack) => { | ||
config.entry.main = './server/index.js' | ||
return config | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Router } from 'express' | ||
|
||
import users from './users' | ||
|
||
const router = Router() | ||
|
||
// Add USERS Routes | ||
router.use(users) | ||
|
||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
const Nuxt = require('nuxt') | ||
const app = require('express')() | ||
import express from 'express' | ||
import { Nuxt, Builder } from 'nuxt' | ||
|
||
import api from './api' | ||
|
||
const app = express() | ||
const host = process.env.HOST || '127.0.0.1' | ||
const port = process.env.PORT || 3000 | ||
|
||
app.set('port', port) | ||
|
||
// Import API Routes | ||
app.use('/api', require('./api/index')) | ||
app.use('/api', api) | ||
|
||
// Import and Set Nuxt.js options | ||
let config = require('./nuxt.config.js') | ||
let config = require('../nuxt.config.js') | ||
config.dev = !(process.env.NODE_ENV === 'production') | ||
|
||
// Init Nuxt.js | ||
const nuxt = new Nuxt(config) | ||
app.use(nuxt.render) | ||
|
||
// Build only in dev mode | ||
if (config.dev) { | ||
nuxt.build() | ||
.catch((error) => { | ||
console.error(error) // eslint-disable-line no-console | ||
process.exit(1) | ||
}) | ||
const builder = new Builder(nuxt) | ||
builder.build() | ||
} | ||
|
||
// Give nuxt middleware to express | ||
app.use(nuxt.render) | ||
|
||
// Listen the server | ||
app.listen(port, host) | ||
console.log('Server listening on ' + host + ':' + port) // eslint-disable-line no-console |
Oops, something went wrong.