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
class CashAmount { | |
constructor(amount) { | |
this.money = amount; | |
} | |
convertToPennies(amount) { | |
let amountString = amount + ''; | |
let first = amountString.split('.')[0] * 100; |
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
class CashAmount { | |
constructor(amount) { | |
this.money = amount; | |
} | |
convertToPennies(amount) { | |
let amountString = amount + ''; | |
let first = amountString.split('.')[0] * 100; |
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
let cache = {}; | |
class App extends React.Component { | |
static async getInitialProps({ req, query, asPath, pathname }) { | |
let data; | |
//if data is in cache then use the cache | |
if (cache[someID]) { | |
data = cache[someID] | |
} else { |
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
import Link from 'next/link' | |
function Home() { | |
return ( | |
<div> | |
Click{' '} | |
<Link href="/about"> | |
<a>here</a> | |
</Link>{' '} | |
to read more |
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
class App extends React.Component { | |
static async getInitialProps({ req, query, asPath, pathname }) { | |
let baseUrl = req ? `${req.protocol}://${req.get("Host")}` : ""; | |
let data = await fetch(baseUrl + 'relativeURL') | |
return { | |
data: data |
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
id | title | content | url | |
---|---|---|---|---|
245 | i love next.js | because... | /post/i-love-nextjs |
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
server.get('/post/:slug', async (req, res) => { | |
const actualPage = "/post"; | |
//get the data using '/post/i-love-nextjs' as the id | |
let data = await fetchDataWithURL(req.params.slug) | |
const postContent = { data: data }; | |
app.render(req, res, actualPage, postContent); | |
}); |
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
function createPageContext() { | |
return { | |
theme, | |
sheetsManager: new Map(), | |
sheetsRegistry: new SheetsRegistry(), | |
//add this to fix broken css in prod | |
generateClassName: createGenerateClassName({ | |
productionPrefix: "prod" |
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
select * from posts where url = '/post/i-love-nextjs' |
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
server.get("/autocomplete/:searchString", async (req, res) => { | |
let cloudSearchEndpoint = 'your endpoint here' | |
let data = await axios.get( | |
` ${endpoint}/2013-01-01/search?q=~${ | |
req.params.searchString | |
}&return=_all_fields%2C_score&highlight.label=%7B%22max_phrases%22%3A3%2C%22format%22%3A%22text%22%2C%22pre_tag%22%3A%22*%23*%22%2C%22post_tag%22%3A%22*%25*%22%7D&highlight.unitcode=%7B%22max_phrases%22%3A3%2C%22format%22%3A%22text%22%2C%22pre_tag%22%3A%22*%23*%22%2C%22post_tag%22%3A%22*%25*%22%7D&sort=_score+desc` | |
); | |
res.send(JSON.stringify(data)); |
OlderNewer