This file contains hidden or 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
Resource.route('moreinfo', { | |
detail: true, | |
handler: (req, res, next) => { | |
// req.params.id holds the resource's id | |
res.send("I'm at /resources/:id/moreinfo!") | |
} | |
}) |
This file contains hidden or 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
Resource.before('post', hash_password).before('put', hash_password) | |
function hash_password(req, res, next) { | |
req.body.password = hash(req.body.password) | |
next() | |
} |
This file contains hidden or 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
Resource.route('recommend', (req, res, next) => { | |
res.send('I have a recommendation for you!') | |
}) |
This file contains hidden or 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
const express = require('express'), | |
restful = require('node-restful'), | |
mongoose = restful.mongoose; | |
const app = express() | |
const Resource = restful.model('resource', mongoose.Schema({ | |
title: 'string', | |
year: 'number', | |
}) | |
.methods(['get', 'post', 'put', 'delete']) |
This file contains hidden or 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
import { Component } from 'react' | |
import Header from '../components/Header' | |
export default class extends Component { | |
static getInitialProps () { | |
return { data: 'My personal blog' } | |
} | |
render () { | |
return ( |
This file contains hidden or 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
import Header from '../components/Header' | |
export default () => ( | |
<div> | |
<Header /> | |
<p>Nextjs love you.</p> | |
</div> | |
) |
This file contains hidden or 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
import Router from 'next/router' | |
export default () => ( | |
<div> | |
<Link href='/'>Home</Link> | |
<Link href='/about'>About</Link> | |
<Link href='/blog'>Blog</Link> | |
</div> | |
) |
This file contains hidden or 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
import Header from '../components/Header' | |
export default () => ( | |
<div> | |
<Header /> | |
<p>React on server-side</p> | |
</div> | |
) |
This file contains hidden or 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
"scripts": { | |
"dev": "next", | |
"build": "next build", | |
"start": "next start" | |
}, |
This file contains hidden or 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
const { graphql, buildSchema } = require('graphql') | |
// Construa um esquema, usando o idioma do esquema GraphQL | |
const schema = buildSchema(` | |
type Query { | |
hello: String | |
} | |
`) | |
// O root fornece uma função de resolução para cada endpoint da API |