Code files

This commit is contained in:
Akhil
2017-07-31 11:33:31 +05:30
parent 073a63ebdd
commit b9ae409ec0
801 changed files with 17535 additions and 0 deletions
@@ -0,0 +1,19 @@
'use strict'
const express = require('express')
const {join} = require('path')
const index = require('./routes/index')
const app = express()
const dev = process.env.NODE_ENV !== 'production'
const port = process.env.PORT || 3000
if (dev) {
app.use(express.static(join(__dirname, 'public')))
}
app.use('/', index)
app.listen(port, () => {
console.log(`Server listening on port ${port}`)
})
@@ -0,0 +1,15 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.2"
}
}
@@ -0,0 +1,4 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
@@ -0,0 +1,15 @@
'use strict'
const {Router} = require('express')
const router = Router()
const views = {
index: require('../views/index')
}
router.get('/', function(req, res, next()) {
const title = 'Express'
res.send(views.index({title}))
next()
})
module.exports = router
@@ -0,0 +1,14 @@
'use strict'
module.exports = function indexView ({title}) {
return `<html>
<head>
<title> ${title} </title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1> ${title} </h1>
<p> Welcome to ${title} </p>
</body>
</html>`
}
@@ -0,0 +1,22 @@
'use strict'
const express = require('express')
const {join} = require('path')
const index = require('./routes/index')
const app = express()
const dev = process.env.NODE_ENV !== 'production'
const port = process.env.PORT || 3000
app.set('views', join(__dirname, 'views'))
app.set('view engine', 'ejs')
if (dev) {
app.use(express.static(join(__dirname, 'public')))
}
app.use('/', index)
app.listen(port, () => {
console.log(`Server listening on port ${port}`)
})
@@ -0,0 +1,16 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ejs": "^2.5.6",
"express": "^4.15.2"
}
}
@@ -0,0 +1,4 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
@@ -0,0 +1,11 @@
'use strict'
const {Router} = require('express')
const router = Router()
router.get('/', function(req, res) {
const title = 'Express'
res.render('index', {title: 'Express'})
})
module.exports = router
@@ -0,0 +1,10 @@
<html>
<head>
<title> <%= title %> </title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1> <%= title %> </h1>
<p> Welcome to <%= title %> </p>
</body>
</html>
@@ -0,0 +1,42 @@
'use strict'
const hapi = require('hapi')
const inert = require('inert')
const vision = require('vision')
const ejs = require('ejs')
const routes = {
index: require('./routes/index'),
devStatic: require('./routes/dev-static')
}
const dev = process.env.NODE_ENV !== 'production'
const port = process.env.PORT || 3000
const server = new hapi.Server()
server.connection({
host: 'localhost',
port: port
})
const plugins = dev ? [vision, inert] : [vision]
server.register(plugins, start)
function start (err) {
if (err) throw err
server.views({
engines: { ejs },
relativeTo: __dirname,
path: 'views'
})
routes.index(server)
if (dev) routes.devStatic(server)
server.start((err) => {
if (err) throw err
console.log(`Server listening on port ${port}`)
})
}
@@ -0,0 +1,18 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ejs": "^2.5.6",
"hapi": "^16.1.1",
"inert": "^4.2.0",
"vision": "^4.1.1"
}
}
@@ -0,0 +1,4 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
@@ -0,0 +1,15 @@
'use strict'
module.exports = devStatic
function devStatic (server) {
server.route({
method: 'GET',
path: '/{param*}',
handler: {
directory: {
path: 'public'
}
}
})
}
@@ -0,0 +1,14 @@
'use strict'
module.exports = index
function index (server) {
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
const title = 'Hapi'
reply.view('index', {title})
}
})
}
@@ -0,0 +1,10 @@
<html>
<head>
<title> <%= title %> </title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1> <%= title %> </h1>
<p> Welcome to <%= title %> </p>
</body>
</html>
@@ -0,0 +1,28 @@
'use strict'
const {join} = require('path')
const Koa = require('koa')
const serve = require('koa-static')
const views = require('koa-views')
const router = require('koa-router')()
const index = require('./routes/index')
const app = new Koa()
const dev = process.env.NODE_ENV !== 'production'
const port = process.env.PORT || 3000
app.use(views(join(__dirname, 'views'), {
extension: 'ejs'
}))
if (dev) {
app.use(serve(join(__dirname, 'public')))
}
router.use('/', index.routes())
app.use(router.routes())
app.listen(port, () => {
console.log(`Server listening on port ${port}`)
})
@@ -0,0 +1,19 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ejs": "^2.5.6",
"koa": "^2.2.0",
"koa-router": "^7.1.1",
"koa-static": "^3.0.0",
"koa-views": "^6.0.1"
}
}
@@ -0,0 +1,4 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
@@ -0,0 +1,17 @@
'use strict'
const router = require('koa-router')()
router.get('/', async function (ctx, next) {
await next()
await ctx.render('index')
}, async (ctx) => ctx.state = {title: 'Koa'})
// simplified:
// router.get('/', async (ctx, next) => {
// await ctx.render('index', {title: 'Koa'})
// })
module.exports = router
@@ -0,0 +1,10 @@
<html>
<head>
<title> <%= title %> </title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1> <%= title %> </h1>
<p> Welcome to <%= title %> </p>
</body>
</html>