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.

61 lines
1.5 KiB

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