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
3 years ago
3 years ago
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. // for parsing application/json
  17. app.use(json());
  18. // for parsing application/x-www-form-urlencoded
  19. app.use(urlencoded());
  20. // adding static files
  21. app.use(serveStatic(join(__dirname, 'public')))
  22. // adding eta as view engine
  23. app.engine('.html', renderFile)
  24. app.set('views', join(__dirname, 'resources/views'))
  25. app.set('view engine', 'html')
  26. // adding http classes for routes
  27. app.use('/', index)
  28. app.use('/bucket', bucket)
  29. app.use('/api/bucket', bucketApi)
  30. app.use((request, response, next) => {
  31. response.setStatus(404)
  32. response.render('errors/404')
  33. })
  34. // let it rain
  35. app.listen(Number(Deno.env.get('SERVER_PORT')))
  36. console.log('running on ' + Deno.env.get('SERVER_PORT'))