You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

3 years ago
  1. import 'https://deno.land/x/dotenv@v2.0.0/load.ts'
  2. import {
  3. opine,
  4. serveStatic,
  5. json,
  6. urlencoded
  7. } from 'https://deno.land/x/opine@1.5.3/mod.ts'
  8. import { dirname, join, createError } from "https://deno.land/x/opine@1.5.3/deps.ts";
  9. import { renderFile } from 'https://deno.land/x/eta@v1.12.2/mod.ts'
  10. // getting routes
  11. import index from './src/http/index.ts'
  12. import bucket from './src/http/bucket.ts'
  13. import bucketApi from './src/http/api/bucket.ts'
  14. const app = opine()
  15. const __dirname = dirname(import.meta.url)
  16. //
  17. app.use(json()); // for parsing application/json
  18. app.use(urlencoded()); // for parsing application/x-www-form-urlencoded
  19. // adding static files
  20. app.use(serveStatic(join(__dirname, 'public')))
  21. // adding eta as view engine
  22. app.engine('.html', renderFile)
  23. app.set('views', join(__dirname, 'resources/views'))
  24. app.set('view engine', 'html')
  25. // adding http classes for routes
  26. app.use('/', index)
  27. app.use('/bucket', bucket)
  28. app.use('/api/bucket', bucketApi)
  29. app.use((request, response, next) => {
  30. response.setStatus(404)
  31. response.render('errors/404')
  32. })
  33. // let it rain
  34. app.listen(Number(Deno.env.get('SERVER_PORT')))
  35. console.log('running on ' + Deno.env.get('SERVER_PORT'))