Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2017
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // server.ts
  2. import * as koa from "koa";
  3. import * as koaRouter from "koa-router";
  4. import * as bodyParser from "koa-bodyparser";
  5. import * as path from "path";
  6. import * as nunjucks from "koa-nunjucks-2";
  7. import * as riot from "riot";
  8. import * as Riot from "riot-typescript";
  9. import * as serve from "koa-send";
  10. // import * as serve from "koa-static";
  11.  
  12. import * from "./HelloWorldTag";
  13.  
  14. const app: koa = new koa();
  15. const router: koaRouter = new koaRouter();
  16.  
  17. //app.use(serve(__dirname + '/public'));
  18. app.use(async function(ctx){
  19.   await serve(ctx, ctx.path, { root: __dirname + '/public' });
  20. })
  21.  
  22. /* Config Nunjucks */
  23. app.use(nunjucks({
  24.     ext: 'njk',
  25.     path: path.join(__dirname, '/views'),
  26.     nunjucksConfig: {
  27.         autoescape: true
  28.     }
  29. }));
  30.  
  31. router.get('/', async function(ctx:any) {
  32.     ctx.render('index');
  33. });
  34.  
  35. app.use(router.routes()).use(router.allowedMethods());
  36. riot.mount('*');
  37. app.listen(3000);
  38. console.log("app listening on port 3000");
  39.  
  40.  
  41. /* index.njk */
  42.  
  43. <!DOCTYPE html>
  44. <html>
  45.     <head>
  46.         <title>Riot JS Learning !</title>
  47.         <script type="text/javascript" src="../js/riot/riot-compiler.min"></script>
  48.         <script type="text/javascript" src="../js/riot-typescript/riot-typescript.js"></script>
  49.         <script type=text/javascript src="../tags/hello-world.js"></script>
  50.     </head>
  51.     <body>
  52.         <h1>Hello ! It's now time to learn Riot JS ! :D</h1>
  53.  
  54.        <hello-world></hello-world>
  55.    </body>
  56. </html>
  57. <script>
  58.    window.onload = function(){main();}
  59. </script>
  60.        
  61. /* TREE */
  62.        
  63. test
  64.     .vscode
  65.     node_modules
  66.  public
  67.     css
  68.    js
  69.         riot
  70.         riot.min.js
  71.        riot-compiler.min.js
  72.      riot-typescript
  73.         riot-typescript.js
  74.    tags
  75.         hello-world.ts
  76.      hello-world.js
  77.  views
  78.     index.njk
  79.  package.json
  80.  server.js
  81.  server.ts
  82.  tsconfig.json
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement