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",
|
"name": "telegram-to-notion-website",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Website for the Telegram to Notion Bot",
|
"description": "Website for the Telegram to Notion Bot",
|
||||||
"main": "index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon index.js",
|
"dev": "nodemon src/index.js",
|
||||||
"start": "node index.js"
|
"start": "node src/index.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"telegram",
|
"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 Express = require('express');
|
||||||
const app = Express()
|
const router = Express.Router()
|
||||||
const port = (process.env.PORT || 3030)
|
|
||||||
|
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
require('dotenv').config()
|
|
||||||
|
|
||||||
const favicon = require('serve-favicon');
|
router.get('/', async (req, res) => {
|
||||||
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) => {
|
|
||||||
|
|
||||||
async function requestAccessToken() {
|
async function requestAccessToken() {
|
||||||
try {
|
try {
|
||||||
@@ -60,7 +44,6 @@ app.get('/auth', async (req, res) => {
|
|||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log("error")
|
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
|
||||||
return {status: 400}
|
return {status: 400}
|
||||||
@@ -69,19 +52,9 @@ app.get('/auth', async (req, res) => {
|
|||||||
|
|
||||||
const response = await requestAccessToken()
|
const response = await requestAccessToken()
|
||||||
|
|
||||||
res.render('auth', {
|
res.status(response.status).json(
|
||||||
name: "fran",
|
response
|
||||||
success: response.status === 200 ? true : false,
|
)
|
||||||
data: response.data
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/privacy-policy', (req, res) => {
|
module.exports = router
|
||||||
res.render('privacy-policy')
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/terms-of-use', (req, res) => {
|
|
||||||
res.render('terms-of-use')
|
|
||||||
})
|
|
||||||
|
|
||||||
app.listen(port, () => console.log('port', port))
|
|
||||||
Reference in New Issue
Block a user