Created
November 26, 2018 11:48
-
-
Save roelvan/034dc9ac570f32021e76f0637e8d46a3 to your computer and use it in GitHub Desktop.
NOW v2 Local DEV env Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config(); | |
const http = require('http'); | |
const url = require('url'); | |
// import NOW SETTINGS | |
const now = require('./now.json'); | |
const PORT = process.env.PORT || 3030; | |
const routes = now.routes.reduce((map, route) => { | |
map[route.src] = require('.' + route.dest); | |
return map; | |
}, {}); | |
http | |
.createServer(async (req, res) => { | |
// filter out any query strings | |
const { pathname } = url.parse(req.url); | |
try { | |
await routes[pathname](req, res); | |
} catch (err) { | |
res.writeHead(404); | |
res.end(); | |
} | |
}) | |
.listen(PORT, () => console.log(`👂 Listening: http://localhost:${PORT}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"routes": [ | |
{ | |
"src": "/auth/local", | |
"methods": ["POST"], | |
"dest": "/api/auth/local/index.js" | |
}, | |
{ | |
"src": "/auth/google", | |
"methods": ["GET"], | |
"dest": "/api/auth/google/index.js" | |
}, | |
{ | |
"src": "/auth/google/callback", | |
"methods": ["GET"], | |
"dest": "/api/auth/google/callback.js" | |
}, | |
{ "src": "/games", "methods": ["GET"], "dest": "/api/games/index.js" } | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment