Skip to content

Commit 9f6f528

Browse files
committed
adding serverless function
1 parent 580707d commit 9f6f528

File tree

15 files changed

+3411
-278
lines changed

15 files changed

+3411
-278
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ node_modules
33
storage/*
44
!storage/.gitkeep
55

6-
.env
6+
.env
7+
# Local Netlify folder
8+
.netlify

config/db.js

Lines changed: 0 additions & 17 deletions
This file was deleted.
File renamed without changes.

functions/api.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const express = require('express')
2+
const app = express()
3+
require('dotenv').config()
4+
const cors = require('cors')
5+
const mongoose = require('mongoose')
6+
const routes = require('../routes')
7+
const serverless = require('serverless-http')
8+
9+
//databse
10+
mongoose
11+
.connect(process.env.MONGO_URL, {
12+
useNewUrlParser: true,
13+
useCreateIndex: true,
14+
useUnifiedTopology: true,
15+
})
16+
.then(() => console.log('DB Connected'))
17+
.catch((err) => console.log(err))
18+
19+
//middleware
20+
21+
app.use(cors())
22+
app.use(express.json())
23+
app.use(express.urlencoded())
24+
25+
//Routes
26+
app.use('/api', routes)
27+
28+
module.exports.handler = serverless(app)

models/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const fileSchema = new Schema(
1111
type: String,
1212
required: true,
1313
},
14-
path: {
14+
url: {
1515
type: String,
1616
required: true,
1717
},

netlify.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[build]
2+
functions='functions'
3+
4+
[[redirects]]
5+
to='/.netlify/functions/api/:splat'
6+
from='/*'
7+
status=200

0 commit comments

Comments
 (0)