-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathhandler.js
127 lines (81 loc) · 2.41 KB
/
handler.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const { Nuxt } = require("nuxt");
const serverless = require("serverless-http");
const express = require("express");
const nuxtConfig = require("./nuxt.config");
// const binaryMimeTypes = require('./binariMimeTypes')
const cors = require("cors");
const app = express();
app.use(cors())
// app.use(bodyParser.json())
// app.use('/api',routes);
// init();
const config = {
...nuxtConfig,
dev: false
};
const nuxt = new Nuxt(config);
app.use("/_nuxt", (req, res) => {
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});
console.log('before redirecting to s3 !!!!!!!!!!!!!!!!!!!!!!!!!!!!' + req.path)
res.redirect(process.env.ASSETS_BUCKET_URL + req.path)
});
app.use("/static", (req, res) =>{
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});
res.redirect(process.env.STATIC_BUCKET_URL + req.path)
});
handlesRequest = async (req, res) => {
let context = {}
let { html } = await nuxt.renderRoute('/', context)
res.send(html);
}
handlesRequestAdmin = async (req, res) => {
let context = {}
let { html } = await nuxt.renderRoute('/admin', context)
res.send(html);
}
handlesRequestBlog = async (req, res) => {
let context = {}
let { html } = await nuxt.renderRoute('/blog', context)
res.send(html);
}
handlesRequestPages = async (req, res) => {
let context = {}
let { html } = await nuxt.renderRoute('/pages', context)
res.send(html);
}
handlesRequestLogin = async (req, res) => {
let context = {}
let { html } = await nuxt.renderRoute('/login', context)
res.send(html);
}
handlesRequestSignup = async (req, res) => {
let context = {}
let { html } = await nuxt.renderRoute('/signup', context)
res.send(html);
}
handlesRequestPostId= async (req, res) => {
let context = {}
let { html } = await nuxt.renderRoute('/post/_id', context)
res.send(html);
}
handlesRequestMenuId = async (req, res) => {
let context = {}
let { html } = await nuxt.renderRoute('/menu/_id', context)
res.send(html);
}
app.get('/', handlesRequest);
app.get('/admin', handlesRequestAdmin);
app.get('/blog', handlesRequestBlog);
app.get('/pages', handlesRequestPages);
app.get('/login', handlesRequestLogin);
app.get('/signup', handlesRequestSignup);
app.get('/post/:id', handlesRequestPostId);
app.get('/menu/:id', handlesRequestMenuId);
app.use(nuxt.render);
exports.renderNUXT =serverless(app);