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.

56 lines
1.5 KiB

  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. // middleware
  11. import session from './src/middleware/session.ts'
  12. // getting routes
  13. import index from './src/http/index.ts'
  14. //import bucket from './src/http/bucket.ts'
  15. //import settings from './src/http/settings.ts'
  16. import users from './src/http/users.ts'
  17. //import bucketApi from './src/http/api/bucket.ts'
  18. //import noteApi from './src/http/api/note.ts'
  19. const app = opine()
  20. const __dirname = dirname(import.meta.url)
  21. // for parsing application/json
  22. app.use(json())
  23. // for parsing application/x-www-form-urlencoded
  24. app.use(urlencoded())
  25. // adding static files
  26. app.use(serveStatic(join(__dirname, 'public')))
  27. // adding eta as view engine
  28. app.engine('.html', renderFile)
  29. app.set('views', join(__dirname, 'resources/views'))
  30. app.set('view engine', 'html')
  31. // adding http classes for routes
  32. app.use('*', session)
  33. app.use('/', index)
  34. //app.use('/bucket', bucket)
  35. //app.use('/settings', settings)
  36. app.use('/users', users)
  37. //app.use('/api/bucket', bucketApi)
  38. //app.use('/api/note', noteApi)
  39. app.use((request, response, next) => {
  40. response.setStatus(404)
  41. response.render('errors/404')
  42. })
  43. // let it rain
  44. app.listen(Number(Deno.env.get('SERVER_PORT')))
  45. console.log('running on ' + Deno.env.get('SERVER_PORT'))