-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsls.js
47 lines (40 loc) · 1.06 KB
/
sls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require('express');
const path = require('path');
const app = express();
app.all('*',(req,res,next)=>{
res.setHeader('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods','PUT,GET,POST,DELETE,OPTIONS');
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header('Access-Control-Allow-Headers','Content-Type');
res.header('Access-Control-Allow-Credentials',true);
next();
})
// Routes
app.get('/user', (req, res) => {
res.send([
{
title: 'serverless framework',
link: 'https://serverless.com',
},
]);
});
app.get('/user/:id', (req, res) => {
const id = req.params.id;
res.send({
id: id,
title: 'serverless framework',
link: 'https://serverless.com',
});
});
app.get('/404', (req, res) => {
res.status(404).send('Not found');
});
app.get('/500', (req, res) => {
res.status(500).send('Server Error');
});
// Error handler
app.use(function (err, req, res, next) {
console.error(err);
res.status(500).send('Internal Serverless Error');
});
module.exports = app;