Guest User

Untitled

a guest
Feb 20th, 2018
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express = require('express');
  2. var morgan = require('morgan');
  3. var path = require('path');
  4.  
  5. var app = express();
  6. app.use(morgan('combined'));
  7.  
  8. var articles={
  9. 'about':{
  10.     title:'Bharath | about',
  11.     heading:'Bharath',
  12.     content:
  13.             `<div class="container">
  14.             <p> I am Bharath Santhakumar,</p>
  15.             <p>S/o Santhakumar</p>
  16.             <p>I am currently learning the basics of internet application and javascript</p>
  17.             <p>This is all about me :-/</p>
  18.             </div>`
  19.    
  20. },
  21.  
  22. 'education':{
  23.     title:'Bharath | education',
  24.     heading:'Bharath Santhakumar',
  25.     content:
  26.             `<div class="container">
  27.                 <table>
  28.                     <tbody>
  29.                         <tr>
  30.                         <th>SI.no</th>
  31.                         <th>Institution</th>
  32.                         </tr>
  33.                         <tr>
  34.                         <td>1</td>
  35.                         <td>Ayira vaisya Secondary school</td>
  36.                         </tr>
  37.                         <tr>
  38.                         <td>2</td>
  39.                         <td>Don Bosco Matriculation School</td>
  40.                         </tr>
  41.                         <tr>
  42.                         <td>3</td>
  43.                         <td>Srv matric higher secondary school</td>
  44.                         </tr>
  45.                         <tr>
  46.                         <td>4</td>
  47.                         <td>Sri manaukula vinayagar enginnering college</td>
  48.                         </tr>
  49.                     </tbody>
  50.                  </table>
  51.             </div>`
  52. }
  53. };
  54.  
  55. function templates(data)
  56. {
  57.     var title=data.title;
  58.     var headings=data.heading;
  59.     var content=data.content;
  60.     var htmltemplate=`<!DOCTYPE html>
  61.                         <html>
  62.                             <head>
  63.                                 <title>${title}</title>
  64.                                 <link href="/ui/style.css" rel="stylesheet" />
  65.                                 <meta name="viewport" content="width=device-width,initial-scale=1" />
  66.                                 <img src="/ui/madi.png" alt="madi" class="img-medium"/>
  67.                             </head>
  68.                             <body>
  69.                                 ${content}
  70.                             </body>
  71.                         </html>`;
  72.     return (htmltemplate);                    
  73. }
  74.  
  75. app.get('/', function (req, res) {
  76.   res.sendFile(path.join(__dirname, 'ui', 'index.html'));
  77. });
  78.  
  79. app.get('/pic', function (req, res) {
  80.   res.sendFile(path.join(__dirname, 'ui', 'pic.jpg'));
  81. });
  82.  
  83. app.get('/:articlename', function (req, res) {
  84.     articlename=req.params.articlename;
  85.   res.send(templates(articles[articlename]));
  86. });
  87.  
  88. var counter=0;
  89.  
  90. app.get('/counter', function (req, res) {
  91.     counter=counter+1;
  92.     res.send(counter.toString());
  93. });
  94.  
  95. app.get('/ui/main.js', function (req, res) {
  96.   res.sendFile(path.join(__dirname, 'ui', 'main.js'));
  97. });
  98.  
  99. app.get('/ui/style.css', function (req, res) {
  100.   res.sendFile(path.join(__dirname, 'ui', 'style.css'));
  101. });
  102.  
  103. app.get('/ui/madi.png', function (req, res) {
  104.   res.sendFile(path.join(__dirname, 'ui', 'madi.png'));
  105. });
  106.  
  107.  
  108.  
  109. // Do not change port, otherwise your app won't run on IMAD servers
  110. // Use 8080 only for local development if you already have apache running on 80
  111.  
  112. var port = 80;
  113. app.listen(port, function () {
  114.   console.log(`IMAD course app listening on port ${port}!`);
  115. });
Add Comment
Please, Sign In to add comment