diff --git a/package.json b/package.json index 1ac8c52..3f6fc2d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..5d1e0a1 --- /dev/null +++ b/src/index.js @@ -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)) diff --git a/index.js b/src/routes/authRouter.js similarity index 66% rename from index.js rename to src/routes/authRouter.js index a02e4f6..15a361f 100644 --- a/index.js +++ b/src/routes/authRouter.js @@ -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)) \ No newline at end of file +module.exports = router \ No newline at end of file