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.

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