Last active
November 23, 2018 12:38
-
-
Save sachinKumarGautam/9868bd96cdd3cddaf162cb3400e17abd to your computer and use it in GitHub Desktop.
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
const express = require('express') | |
const next = require('next') | |
const cookieParser = require('cookie-parser') | |
const dev = process.env.NODE_ENV !== 'production' | |
const app = next({ dev }) | |
const handle = app.getRequestHandler() | |
const url = require('url') | |
const path = require('path') | |
const expressApp = express() | |
const appDeepLink = require('./appDeepLink') | |
const PRERENDER_SERVICE_URL = 'http://localhost:3001' | |
const prerenderNode = require('prerender-node') | |
.set('prerenderToken', 'OXuymwur28y7tZPGcg0x') | |
.set('protocol', 'https').set('host', 'www.lifcare.in') | |
prerenderNode.crawlerUserAgents.push('googlebot') | |
prerenderNode.crawlerUserAgents.push('bingbot') | |
prerenderNode.crawlerUserAgents.push('yandex') | |
// require('prerender-node').set('prerenderServiceUrl', 'https://35.244.33.91/') | |
prepareNextApplication() | |
async function prepareNextApplication () { | |
await app | |
.prepare() | |
.then(() => { | |
const server = express() | |
// server.use( | |
// require('prerender-node').set( | |
// 'prerenderServiceUrl', | |
// PRERENDER_SERVICE_URL | |
// ) | |
// ) | |
server.use(prerenderNode) | |
server.use(cookieParser()) | |
const options = { | |
root: path.join(__dirname, '/static'), | |
headers: { | |
'Content-Type': 'text/plain;charset=UTF-8' | |
} | |
} | |
server.get('/robots.txt', (req, res) => | |
res.status(200).sendFile('robots.txt', options) | |
) | |
// APNs site assicaitions | |
server.get('/apple-app-site-association', function (req, res) { | |
res.sendFile(appDeepLink.apnsAssociations, { root: __dirname }) | |
}) | |
// Android verified links | |
server.get('/.well-known/assetlinks.json', function (req, res) { | |
res.sendFile(appDeepLink.androidVerifiedAppLinks, { root: __dirname }) | |
}) | |
// molecule details page | |
server.get('/product/molecule/:id', (req, res) => { | |
const actualPage = '/molecule-details' | |
const queryParams = { molecule_id: req.params.id } | |
app.render(req, res, actualPage, queryParams) | |
}) | |
// medicine list page | |
server.get('/product/search', (req, res) => { | |
const actualPage = '/medicine-list' | |
const queryParams = { | |
productName: req.query.slug, | |
moleculeName: req.query['molecule-name'] | |
} | |
app.render(req, res, actualPage, queryParams) | |
}) | |
// product details page | |
server.get('/product/:id', (req, res) => { | |
const actualPage = '/product-details' | |
const queryParams = { | |
product_id: req.params.id, | |
location: req.query.location | |
} | |
app.render(req, res, actualPage, queryParams) | |
}) | |
// refill patients page | |
server.get('/customer/:id/patient-refills', (req, res) => { | |
const actualPage = '/refill-patients' | |
const queryParams = { customer_id: req.params.id } | |
if (!req.cookies.token) { | |
res.redirect( | |
url.format({ | |
pathname: '/', | |
query: { | |
authentication: false, | |
path: req.originalUrl | |
} | |
}) | |
) | |
} else { | |
app.render(req, res, actualPage, queryParams) | |
} | |
}) | |
// patient list page | |
server.get('/customer/:id/patients', (req, res) => { | |
const actualPage = '/patient-details' | |
const queryParams = { customer_id: req.params.id } | |
if (!req.cookies.token) { | |
res.redirect( | |
url.format({ | |
pathname: '/', | |
query: { | |
authentication: false, | |
path: req.originalUrl | |
} | |
}) | |
) | |
} else { | |
app.render(req, res, actualPage, queryParams) | |
} | |
}) | |
// shipping address list page | |
server.get('/customer/:id/delivery-addresses', (req, res) => { | |
const actualPage = '/delivery-details' | |
const queryParams = { customer_id: req.params.id } | |
if (!req.cookies.token) { | |
res.redirect( | |
url.format({ | |
pathname: '/', | |
query: { | |
authentication: false, | |
path: req.originalUrl | |
} | |
}) | |
) | |
} else { | |
app.render(req, res, actualPage, queryParams) | |
} | |
}) | |
// order list page | |
server.get('/customer/:id/orders', (req, res) => { | |
const actualPage = '/order-list' | |
const queryParams = { customer_id: req.params.id } | |
if (!req.cookies.token) { | |
res.redirect( | |
url.format({ | |
pathname: '/', | |
query: { | |
authentication: false, | |
path: req.originalUrl | |
} | |
}) | |
) | |
} else { | |
app.render(req, res, actualPage, queryParams) | |
} | |
}) | |
// prescription list page | |
server.get('/customer/:id/prescriptions', (req, res) => { | |
const actualPage = '/prescription-list' | |
const queryParams = { customer_id: req.params.id } | |
if (!req.cookies.token) { | |
res.redirect( | |
url.format({ | |
pathname: '/', | |
query: { | |
authentication: false, | |
path: req.originalUrl | |
} | |
}) | |
) | |
} else { | |
app.render(req, res, actualPage, queryParams) | |
} | |
}) | |
// care points list page | |
server.get('/customer/:id/care-points', (req, res) => { | |
const actualPage = '/care-points' | |
const queryParams = { customer_id: req.params.id } | |
if (!req.cookies.token) { | |
res.redirect( | |
url.format({ | |
pathname: '/', | |
query: { | |
authentication: false, | |
path: req.originalUrl | |
} | |
}) | |
) | |
} else { | |
app.render(req, res, actualPage, queryParams) | |
} | |
}) | |
// cart page | |
server.get('/cart/:id', (req, res) => { | |
const actualPage = '/cart-details' | |
const queryParams = { id: req.params.id } | |
app.render(req, res, actualPage, queryParams) | |
}) | |
// thank you page | |
server.get('/order/:id/order-confirmation', (req, res) => { | |
const actualPage = '/order-confirmation' | |
const queryParams = { | |
id: req.params.id, | |
paymentStatus: req.query['payment-status'] | |
} | |
if (!req.cookies.token) { | |
res.redirect( | |
url.format({ | |
pathname: '/', | |
query: { | |
authentication: false, | |
path: req.originalUrl | |
} | |
}) | |
) | |
} else { | |
app.render(req, res, actualPage, queryParams) | |
} | |
}) | |
// order details page | |
server.get('/order/:id', (req, res) => { | |
const actualPage = '/order-details' | |
const queryParams = { id: req.params.id } | |
app.render(req, res, actualPage, queryParams) | |
}) | |
// privacy policy page | |
server.get('/company/privacy', (req, res) => { | |
const actualPage = '/privacy' | |
app.render(req, res, actualPage) | |
}) | |
// about us page | |
server.get('/company/about', (req, res) => { | |
const actualPage = '/about' | |
app.render(req, res, actualPage) | |
}) | |
// faq page | |
server.get('/company/faq', (req, res) => { | |
const actualPage = '/faq' | |
app.render(req, res, actualPage) | |
}) | |
// faq page | |
server.get('/company/terms', (req, res) => { | |
const actualPage = '/terms' | |
app.render(req, res, actualPage) | |
}) | |
// home page | |
server.get('/', (req, res) => { | |
const actualPage = '/' | |
const queryParams = { | |
authentication: req.query.authentication, | |
path: req.query.path | |
} | |
app.render(req, res, actualPage, queryParams) | |
}) | |
server.get('*', (req, res) => { | |
return handle(req, res) | |
}) | |
server.listen(3000, err => { | |
if (err) throw err | |
console.log('> Ready on http://localhost:3000') | |
}) | |
}) | |
.catch(ex => { | |
console.error(ex.stack) | |
process.exit(1) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment