Skip to content

Instantly share code, notes, and snippets.

@ChrisCates
Created January 26, 2024 00:41
Show Gist options
  • Save ChrisCates/8f983ca34b75cfc9b7e7d66b4a3f7300 to your computer and use it in GitHub Desktop.
Save ChrisCates/8f983ca34b75cfc9b7e7d66b4a3f7300 to your computer and use it in GitHub Desktop.
Vercel Configuration for Typescript Express Servers
import 'colors'
import { config } from 'dotenv'
import { createServer } from 'http'
import morgan from 'morgan'
import cors from 'cors'
import Express from 'express'
import BodyParser from 'body-parser'
import { testRoute } from 'api/route/test'
config()
process.env.TZ = 'America/New_York'
export const PORT = Number(process.env.PORT || '4242')
export const api = Express()
export const server = createServer(api)
api.use(cors())
api.use(BodyParser.json())
api.use(BodyParser.urlencoded({ extended: true }))
api.use(morgan('tiny'))
api.get('/', (req, res) => {
return res.status(200).send('OK')
})
api.post('/test', testRoute)
module.exports = server
{
"compilerOptions": {
"target": "ES6",
"lib": ["ESNext"],
"baseUrl": "./",
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "CommonJS",
"moduleResolution": "Node",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"composite": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false
},
"include": ["api/**/*.ts"],
"exclude": ["node_modules"]
}
{
"version": 2,
"builds": [
{
"src": "api/server.ts",
"use": "@vercel/node",
"config": { "includeFiles": ["api/**"] }
}
],
"routes": [
{
"src": "/(.*)",
"dest": "api/server.ts"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment