Skip to content

Commit

Permalink
ready to production
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefomar724 committed Jul 13, 2022
1 parent 3cd6b24 commit 576d33f
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 6 deletions.
1 change: 1 addition & 0 deletions components/most-watched/MostWatched.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const MostWatched = ({ title, sectionClass, posts }) => {
<Link
href={`/post/${item.id}-${item.post_title
.trim()
.slice(0, 20)
.split(' ')
.join('-')}`}
>
Expand Down
1 change: 1 addition & 0 deletions components/news-item/NewsItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const NewsItems = () => {
<Link
href={`/post/${item.id}-${item.post_title
.trim()
.slice(0, 20)
.split(' ')
.join('-')}`}
>
Expand Down
12 changes: 10 additions & 2 deletions components/syria-news/SyriaNews.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ const SyriaNews = ({ posts }) => {
<Link
href={`/post/${
posts.blog_post[0].id
}-${posts.blog_post[0].post_title.trim().split(' ').join('-')}`}
}-${posts.blog_post[0].post_title
.trim()
.slice(0, 20)
.split(' ')
.join('-')}`}
>
<a>
<h3
Expand Down Expand Up @@ -62,7 +66,11 @@ const SyriaNews = ({ posts }) => {
<Link
href={`/post/${
posts.blog_post[0].id
}-${posts.blog_post[0].post_title.trim().split(' ').join('-')}`}
}-${posts.blog_post[0].post_title
.trim()
.slice(0, 20)
.split(' ')
.join('-')}`}
>
<a>
<Toast.Body>
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "node server.js",
"build": "next build",
"start": "next start",
"lint": "next lint"
"start": "NODE_ENV=production node server.js"
},
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
Expand Down
8 changes: 7 additions & 1 deletion pages/post/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ export const getStaticPaths = async () => {
const allPosts = await data.json()

const paths = allPosts?.blog_post.map((post) => ({
params: { id: `${post.id}-${post.post_title.trim().split(' ').join('-')}` },
params: {
id: `${post.id}-${post.post_title
.trim()
.slice(0, 20)
.split(' ')
.join('-')}`,
},
}))

return { paths, fallback: false }
Expand Down
37 changes: 37 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// server.js
const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const hostname = 'localhost'
const port = 3000
// when using middleware `hostname` and `port` must be provided below
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()

app.prepare().then(() => {
createServer(async (req, res) => {
try {
// Be sure to pass `true` as the second argument to `url.parse`.
// This tells it to parse the query portion of the URL.
const parsedUrl = parse(req.url, true)
const { pathname, query } = parsedUrl

if (pathname === '/a') {
await app.render(req, res, '/a', query)
} else if (pathname === '/b') {
await app.render(req, res, '/b', query)
} else {
await handle(req, res, parsedUrl)
}
} catch (err) {
console.error('Error occurred handling', req.url, err)
res.statusCode = 500
res.end('internal server error')
}
}).listen(port, (err) => {
if (err) throw err
console.log(`> Ready on http://${hostname}:${port}`)
})
})
Binary file added syria-exchange-next.zip
Binary file not shown.

0 comments on commit 576d33f

Please sign in to comment.