mirror of
https://github.com/FranP-code/Open-Telegram-to-Notion-Backend.git
synced 2025-10-12 23:52:54 +00:00
API structure done
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
"name": "telegram-to-notion-website",
|
||||
"version": "1.0.0",
|
||||
"description": "Website for the Telegram to Notion Bot",
|
||||
"main": "index.js",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon index.js",
|
||||
"start": "node index.js"
|
||||
"dev": "nodemon src/index.js",
|
||||
"start": "node src/index.js"
|
||||
},
|
||||
"keywords": [
|
||||
"telegram",
|
||||
|
||||
35
src/index.js
Normal file
35
src/index.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const Express = require('express')
|
||||
const app = Express()
|
||||
const port = (process.env.PORT || 3030)
|
||||
require('dotenv').config()
|
||||
|
||||
//Configure Handlebars
|
||||
const hbs = require('hbs')
|
||||
hbs.registerPartials(__dirname + '/../views/partials')
|
||||
app.set('view engine', 'hbs')
|
||||
|
||||
//Use public folder
|
||||
app.use(Express.static('public'));
|
||||
|
||||
//Create master route
|
||||
const masterRoute = Express.Router()
|
||||
|
||||
app.use('/api/v1', masterRoute)
|
||||
|
||||
//Import routes
|
||||
const auth = require('./routes/authRouter.js')
|
||||
masterRoute.use('/auth', auth)
|
||||
|
||||
masterRoute.get('/', (req, res) => {
|
||||
res.send('Welcome to the Telegram to Notion Bot Backend!')
|
||||
})
|
||||
|
||||
masterRoute.get('/privacy-policy', (req, res) => {
|
||||
res.render('privacy-policy')
|
||||
})
|
||||
|
||||
masterRoute.get('/terms-of-use', (req, res) => {
|
||||
res.render('terms-of-use')
|
||||
})
|
||||
|
||||
app.listen(port, () => console.log('port', port))
|
||||
@@ -1,25 +1,9 @@
|
||||
const Express = require('express')
|
||||
const app = Express()
|
||||
const port = (process.env.PORT || 3030)
|
||||
const Express = require('express');
|
||||
const router = Express.Router()
|
||||
|
||||
const axios = require('axios')
|
||||
require('dotenv').config()
|
||||
|
||||
const favicon = require('serve-favicon');
|
||||
app.use(favicon(__dirname + '/public/favicon.ico'));
|
||||
|
||||
const hbs = require('hbs')
|
||||
|
||||
hbs.registerPartials(__dirname + '/views/partials')
|
||||
app.set('view engine', 'hbs')
|
||||
|
||||
app.use(Express.static('public'));
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.render('index')
|
||||
})
|
||||
|
||||
app.get('/auth', async (req, res) => {
|
||||
router.get('/', async (req, res) => {
|
||||
|
||||
async function requestAccessToken() {
|
||||
try {
|
||||
@@ -60,7 +44,6 @@ app.get('/auth', async (req, res) => {
|
||||
return response
|
||||
}
|
||||
catch (error) {
|
||||
console.log("error")
|
||||
console.log(error)
|
||||
|
||||
return {status: 400}
|
||||
@@ -69,19 +52,9 @@ app.get('/auth', async (req, res) => {
|
||||
|
||||
const response = await requestAccessToken()
|
||||
|
||||
res.render('auth', {
|
||||
name: "fran",
|
||||
success: response.status === 200 ? true : false,
|
||||
data: response.data
|
||||
})
|
||||
res.status(response.status).json(
|
||||
response
|
||||
)
|
||||
})
|
||||
|
||||
app.get('/privacy-policy', (req, res) => {
|
||||
res.render('privacy-policy')
|
||||
})
|
||||
|
||||
app.get('/terms-of-use', (req, res) => {
|
||||
res.render('terms-of-use')
|
||||
})
|
||||
|
||||
app.listen(port, () => console.log('port', port))
|
||||
module.exports = router
|
||||
Reference in New Issue
Block a user